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
|
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* fm-directory-view.c
*
* Copyright (C) 1999, 2000 Free Software Foundaton
* Copyright (C) 2000 Eazel, Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* Authors: Ettore Perazzoli,
* John Sullivan <sullivan@eazel.com>,
* Darin Adler <darin@eazel.com>
* Pavel Cisler <pavel@eazel.com>
*/
#include <config.h>
#include "fm-directory-view.h"
#include "fm-desktop-icon-view.h"
#include "fm-properties-window.h"
#include "nautilus-trash-monitor.h"
#include <bonobo/bonobo-control.h>
#include <gtk/gtkcheckmenuitem.h>
#include <gtk/gtkmain.h>
#include <gtk/gtkmenu.h>
#include <gtk/gtksignal.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomeui/gnome-uidefs.h>
#include <libgnomevfs/gnome-vfs-async-ops.h>
#include <libgnomevfs/gnome-vfs-directory-list.h>
#include <libgnomevfs/gnome-vfs-file-info.h>
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
#include <libgnomevfs/gnome-vfs-result.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-utils.h>
#include <libnautilus-extensions/nautilus-background.h>
#include <libnautilus-extensions/nautilus-bonobo-extensions.h>
#include <libnautilus-extensions/nautilus-directory-background.h>
#include <libnautilus-extensions/nautilus-directory.h>
#include <libnautilus-extensions/nautilus-drag.h>
#include <libnautilus-extensions/nautilus-file-attributes.h>
#include <libnautilus-extensions/nautilus-file-operations.h>
#include <libnautilus-extensions/nautilus-file-utilities.h>
#include <libnautilus-extensions/nautilus-glib-extensions.h>
#include <libnautilus-extensions/nautilus-global-preferences.h>
#include <libnautilus-extensions/nautilus-gnome-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-extensions.h>
#include <libnautilus-extensions/nautilus-gtk-macros.h>
#include <libnautilus-extensions/nautilus-icon-factory.h>
#include <libnautilus-extensions/nautilus-link.h>
#include <libnautilus-extensions/nautilus-metadata.h>
#include <libnautilus-extensions/nautilus-mime-actions.h>
#include <libnautilus-extensions/nautilus-program-choosing.h>
#include <libnautilus-extensions/nautilus-stock-dialogs.h>
#include <libnautilus-extensions/nautilus-string.h>
#include <libnautilus-extensions/nautilus-view-identifier.h>
#include <libnautilus/nautilus-bonobo-ui.h>
#include <libnautilus/nautilus-zoomable.h>
#include <math.h>
#include <src/nautilus-application.h>
#define DISPLAY_TIMEOUT_INTERVAL_MSECS 500
#define SILENT_WINDOW_OPEN_LIMIT 10
/* Paths to use when referring to bonobo menu items. */
#define FM_DIRECTORY_VIEW_MENU_PATH_OPEN "/menu/File/Open Placeholder/Open"
#define FM_DIRECTORY_VIEW_MENU_PATH_OPEN_IN_NEW_WINDOW "/menu/File/Open Placeholder/OpenNew"
#define FM_DIRECTORY_VIEW_MENU_PATH_OPEN_WITH "/menu/File/Open Placeholder/Open With"
#define FM_DIRECTORY_VIEW_MENU_PATH_NEW_FOLDER "/menu/File/New Items Placeholder/New Folder"
#define FM_DIRECTORY_VIEW_MENU_PATH_DELETE "/menu/File/File Items Placeholder/Delete"
#define FM_DIRECTORY_VIEW_MENU_PATH_TRASH "/menu/File/File Items Placeholder/Trash"
#define FM_DIRECTORY_VIEW_MENU_PATH_EMPTY_TRASH "/menu/File/Global File Items Placeholder/Empty Trash"
#define FM_DIRECTORY_VIEW_MENU_PATH_DUPLICATE "/menu/File/File Items Placeholder/Duplicate"
#define FM_DIRECTORY_VIEW_MENU_PATH_CREATE_LINK "/menu/File/File Items Placeholder/Create Link"
#define FM_DIRECTORY_VIEW_MENU_PATH_SHOW_PROPERTIES "/menu/File/File Items Placeholder/Show Properties"
#define FM_DIRECTORY_VIEW_MENU_PATH_RESET_BACKGROUND "/menu/Edit/Global Edit Items Placeholder/Reset Background"
#define FM_DIRECTORY_VIEW_MENU_PATH_REMOVE_CUSTOM_ICONS "/menu/Edit/Edit Items Placeholder/Remove Custom Icons"
#define FM_DIRECTORY_VIEW_MENU_PATH_APPLICATIONS_PLACEHOLDER "/menu/File/Open Placeholder/Open With/Applications Placeholder"
#define FM_DIRECTORY_VIEW_MENU_PATH_OTHER_APPLICATION "/menu/File/Open Placeholder/Open With/OtherApplication"
#define FM_DIRECTORY_VIEW_MENU_PATH_VIEWERS_PLACEHOLDER "/menu/File/Open Placeholder/Open With/Viewers Placeholder"
#define FM_DIRECTORY_VIEW_MENU_PATH_OTHER_VIEWER "/menu/File/Open Placeholder/Open With/OtherViewer"
enum {
ADD_FILE,
CREATE_BACKGROUND_CONTEXT_MENU_ITEMS,
CREATE_SELECTION_CONTEXT_MENU_ITEMS,
BEGIN_ADDING_FILES,
BEGIN_LOADING,
CLEAR,
DONE_ADDING_FILES,
FILE_CHANGED,
MOVE_COPY_ITEMS,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL];
struct FMDirectoryViewDetails
{
NautilusView *nautilus_view;
NautilusZoomable *zoomable;
NautilusDirectory *model;
NautilusFile *directory_as_file;
BonoboUIComponent *ui;
guint display_selection_idle_id;
guint update_menus_idle_id;
guint display_pending_timeout_id;
guint display_pending_idle_id;
guint files_added_handler_id;
guint files_changed_handler_id;
GList *pending_files_added;
GList *pending_files_changed;
GList *pending_uris_selected;
gboolean loading;
gboolean menus_merged;
gboolean menu_states_untrustworthy;
gboolean show_hidden_files;
gboolean show_backup_files;
gboolean batching_selection_level;
gboolean selection_changed_while_batched;
};
/* forward declarations */
static int display_selection_info_idle_callback (gpointer data);
static gboolean file_is_launchable (NautilusFile *file);
static void fm_directory_view_initialize_class (FMDirectoryViewClass *klass);
static void fm_directory_view_initialize (FMDirectoryView *view);
static void fm_directory_view_duplicate_selection (FMDirectoryView *view,
GList *files);
static void fm_directory_view_create_links_for_files (FMDirectoryView *view,
GList *files);
static void fm_directory_view_trash_or_delete_files (FMDirectoryView *view,
GList *files);
static void fm_directory_view_destroy (GtkObject *object);
static void fm_directory_view_activate_file (FMDirectoryView *view,
NautilusFile *file,
gboolean use_new_window);
static void fm_directory_view_create_background_context_menu_items (FMDirectoryView *view,
GtkMenu *menu);
static void fm_directory_view_load_uri (FMDirectoryView *view,
const char *uri);
static void fm_directory_view_merge_menus (FMDirectoryView *view);
static void fm_directory_view_real_create_background_context_menu_items (FMDirectoryView *view,
GtkMenu *menu);
static void fm_directory_view_real_create_selection_context_menu_items (FMDirectoryView *view,
GtkMenu *menu,
GList *files);
static void fm_directory_view_real_merge_menus (FMDirectoryView *view);
static void fm_directory_view_real_update_menus (FMDirectoryView *view);
static gboolean fm_directory_view_real_is_read_only (FMDirectoryView *view);
static gboolean fm_directory_view_real_supports_creating_files (FMDirectoryView *view);
static gboolean fm_directory_view_real_accepts_dragged_files (FMDirectoryView *view);
static gboolean fm_directory_view_real_supports_zooming (FMDirectoryView *view);
static gboolean fm_directory_view_real_supports_properties (FMDirectoryView *view);
static GtkMenu * create_selection_context_menu (FMDirectoryView *view);
static GtkMenu * create_background_context_menu (FMDirectoryView *view);
static BonoboControl *get_bonobo_control (FMDirectoryView *view);
static void stop_loading_callback (NautilusView *nautilus_view,
FMDirectoryView *directory_view);
static void load_location_callback (NautilusView *nautilus_view,
const char *location,
FMDirectoryView *directory_view);
static void selection_changed_callback (NautilusView *nautilus_view,
GList *selection,
FMDirectoryView *directory_view);
static void open_one_in_new_window (gpointer data,
gpointer callback_data);
static void open_one_properties_window (gpointer data,
gpointer callback_data);
static void zoomable_set_zoom_level_callback (NautilusZoomable *zoomable,
double level,
FMDirectoryView *view);
static void zoomable_zoom_in_callback (NautilusZoomable *zoomable,
FMDirectoryView *directory_view);
static void zoomable_zoom_out_callback (NautilusZoomable *zoomable,
FMDirectoryView *directory_view);
static void zoomable_zoom_to_fit_callback (NautilusZoomable *zoomable,
FMDirectoryView *directory_view);
static void schedule_update_menus (FMDirectoryView *view);
static void schedule_update_menus_callback (gpointer callback_data);
static void schedule_idle_display_of_pending_files (FMDirectoryView *view);
static void unschedule_idle_display_of_pending_files (FMDirectoryView *view);
static void schedule_timeout_display_of_pending_files (FMDirectoryView *view);
static void unschedule_timeout_display_of_pending_files (FMDirectoryView *view);
static void unschedule_display_of_pending_files (FMDirectoryView *view);
static void disconnect_model_handlers (FMDirectoryView *view);
static void filtering_changed_callback (gpointer callback_data);
static void get_required_metadata_keys (FMDirectoryView *view,
GList **directory_keys_result,
GList **file_keys_result);
static NautilusStringList * real_get_emblem_names_to_exclude (FMDirectoryView *view);
static void start_renaming_item (FMDirectoryView *view,
const char *uri);
static void metadata_ready_callback (NautilusDirectory *directory,
GList *files,
gpointer callback_data);
static void fm_directory_view_trash_state_changed_callback (NautilusTrashMonitor *trash,
gboolean state,
gpointer callback_data);
NAUTILUS_DEFINE_CLASS_BOILERPLATE (FMDirectoryView, fm_directory_view, GTK_TYPE_SCROLLED_WINDOW)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, add_file)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, bump_zoom_level)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, zoom_to_level)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, restore_default_zoom_level)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, can_zoom_in)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, can_zoom_out)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, get_background_widget)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, clear)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, file_changed)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, get_selection)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, is_empty)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, select_all)
NAUTILUS_IMPLEMENT_MUST_OVERRIDE_SIGNAL (fm_directory_view, set_selection)
static void
fm_directory_view_initialize_class (FMDirectoryViewClass *klass)
{
GtkObjectClass *object_class;
object_class = GTK_OBJECT_CLASS (klass);
object_class->destroy = fm_directory_view_destroy;
signals[CLEAR] =
gtk_signal_new ("clear",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (FMDirectoryViewClass, clear),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
signals[BEGIN_ADDING_FILES] =
gtk_signal_new ("begin_adding_files",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (FMDirectoryViewClass, begin_adding_files),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
signals[ADD_FILE] =
gtk_signal_new ("add_file",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (FMDirectoryViewClass, add_file),
gtk_marshal_NONE__BOXED,
GTK_TYPE_NONE, 1, GTK_TYPE_BOXED);
signals[FILE_CHANGED] =
gtk_signal_new ("file_changed",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (FMDirectoryViewClass, file_changed),
gtk_marshal_NONE__BOXED,
GTK_TYPE_NONE, 1, GTK_TYPE_BOXED);
signals[DONE_ADDING_FILES] =
gtk_signal_new ("done_adding_files",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (FMDirectoryViewClass, done_adding_files),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
signals[BEGIN_LOADING] =
gtk_signal_new ("begin_loading",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (FMDirectoryViewClass, begin_loading),
gtk_marshal_NONE__NONE,
GTK_TYPE_NONE, 0);
signals[CREATE_SELECTION_CONTEXT_MENU_ITEMS] =
gtk_signal_new ("create_selection_context_menu_items",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (FMDirectoryViewClass, create_selection_context_menu_items),
nautilus_gtk_marshal_NONE__BOXED_BOXED,
GTK_TYPE_NONE, 2, GTK_TYPE_BOXED, GTK_TYPE_BOXED);
signals[CREATE_BACKGROUND_CONTEXT_MENU_ITEMS] =
gtk_signal_new ("create_background_context_menu_items",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (FMDirectoryViewClass, create_background_context_menu_items),
gtk_marshal_NONE__BOXED,
GTK_TYPE_NONE, 1, GTK_TYPE_BOXED);
klass->create_selection_context_menu_items = fm_directory_view_real_create_selection_context_menu_items;
klass->create_background_context_menu_items = fm_directory_view_real_create_background_context_menu_items;
klass->merge_menus = fm_directory_view_real_merge_menus;
klass->update_menus = fm_directory_view_real_update_menus;
klass->get_required_metadata_keys = get_required_metadata_keys;
klass->get_emblem_names_to_exclude = real_get_emblem_names_to_exclude;
klass->start_renaming_item = start_renaming_item;
klass->is_read_only = fm_directory_view_real_is_read_only;
klass->supports_creating_files = fm_directory_view_real_supports_creating_files;
klass->accepts_dragged_files = fm_directory_view_real_accepts_dragged_files;
klass->supports_zooming = fm_directory_view_real_supports_zooming;
klass->supports_properties = fm_directory_view_real_supports_properties;
klass->reveal_selection = NULL;
/* Function pointers that subclasses must override */
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, add_file);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, bump_zoom_level);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, zoom_to_level);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, restore_default_zoom_level);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, can_zoom_in);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, can_zoom_out);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, get_background_widget);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, clear);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, file_changed);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, get_selection);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, is_empty);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, select_all);
NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, fm_directory_view, set_selection);
gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL);
}
typedef struct {
GnomeVFSMimeApplication *application;
char *uri;
FMDirectoryView *directory_view;
} ApplicationLaunchParameters;
typedef struct {
NautilusViewIdentifier *identifier;
char *uri;
FMDirectoryView *directory_view;
} ViewerLaunchParameters;
static ApplicationLaunchParameters *
application_launch_parameters_new (GnomeVFSMimeApplication *application,
const char *uri,
FMDirectoryView *directory_view)
{
ApplicationLaunchParameters *result;
result = g_new0 (ApplicationLaunchParameters, 1);
result->application = gnome_vfs_mime_application_copy (application);
gtk_widget_ref (GTK_WIDGET (directory_view));
result->directory_view = directory_view;
result->uri = g_strdup (uri);
return result;
}
static void
application_launch_parameters_free (ApplicationLaunchParameters *parameters)
{
gnome_vfs_mime_application_free (parameters->application);
gtk_widget_unref (GTK_WIDGET (parameters->directory_view));
g_free (parameters->uri);
g_free (parameters);
}
static ViewerLaunchParameters *
viewer_launch_parameters_new (NautilusViewIdentifier *identifier,
const char *uri,
FMDirectoryView *directory_view)
{
ViewerLaunchParameters *result;
result = g_new0 (ViewerLaunchParameters, 1);
result->identifier = nautilus_view_identifier_copy (identifier);
gtk_widget_ref (GTK_WIDGET (directory_view));
result->directory_view = directory_view;
result->uri = g_strdup (uri);
return result;
}
static void
viewer_launch_parameters_free (ViewerLaunchParameters *parameters)
{
nautilus_view_identifier_free (parameters->identifier);
gtk_widget_unref (GTK_WIDGET (parameters->directory_view));
g_free (parameters->uri);
g_free (parameters);
}
static GtkWindow *
get_containing_window (FMDirectoryView *view)
{
g_assert (FM_IS_DIRECTORY_VIEW (view));
return GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
}
gboolean
fm_directory_view_confirm_multiple_windows (FMDirectoryView *view, int count)
{
GnomeDialog *dialog;
char *prompt;
char *title;
if (count <= SILENT_WINDOW_OPEN_LIMIT) {
return TRUE;
}
prompt = g_strdup_printf (_("This will open %d separate windows. "
"Are you sure you want to do this?"), count);
title = g_strdup_printf (_("Open %d Windows?"), count);
dialog = nautilus_yes_no_dialog (prompt, title,
GNOME_STOCK_BUTTON_OK,
GNOME_STOCK_BUTTON_CANCEL,
get_containing_window (view));
g_free (prompt);
g_free (title);
return gnome_dialog_run (dialog) == GNOME_OK;
}
static gboolean
selection_contains_one_item_in_menu_callback (FMDirectoryView *view, GList *selection)
{
if (nautilus_g_list_exactly_one_item (selection)) {
return TRUE;
}
/* If we've requested a menu update that hasn't yet occurred, then
* the mismatch here doesn't surprise us, and we won't complain.
* Otherwise, we will complain.
*/
if (!view->details->menu_states_untrustworthy) {
g_warning ("expected one selected item, found %d",
g_list_length (selection));
}
return FALSE;
}
static gboolean
selection_not_empty_in_menu_callback (FMDirectoryView *view, GList *selection)
{
if (selection != NULL) {
return TRUE;
}
/* If we've requested a menu update that hasn't yet occurred, then
* the mismatch here doesn't surprise us, and we won't complain.
* Otherwise, we will complain.
*/
if (!view->details->menu_states_untrustworthy) {
g_warning ("empty selection found when selection was expected");
}
return FALSE;
}
/**
* Note that this is used both as a Bonobo menu callback and a signal callback.
* The first parameter is different in these cases, but we just ignore it anyway.
*/
static void
open_callback (gpointer ignored, gpointer callback_data)
{
FMDirectoryView *view;
GList *selection;
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
view = FM_DIRECTORY_VIEW (callback_data);
selection = fm_directory_view_get_selection (view);
/* UI should have prevented this from being called unless exactly
* one item is selected.
*/
if (selection_contains_one_item_in_menu_callback (view, selection)) {
fm_directory_view_activate_file (view,
NAUTILUS_FILE (selection->data),
FALSE);
}
nautilus_file_list_free (selection);
}
/**
* Note that this is used both as a Bonobo menu callback and a signal callback.
* The first parameter is different in these cases, but we just ignore it anyway.
*/
static void
open_in_new_window_callback (gpointer ignored, gpointer callback_data)
{
FMDirectoryView *view;
GList *selection;
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
view = FM_DIRECTORY_VIEW (callback_data);
selection = fm_directory_view_get_selection (view);
if (fm_directory_view_confirm_multiple_windows (view, g_list_length (selection))) {
g_list_foreach (selection, open_one_in_new_window, view);
}
nautilus_file_list_free (selection);
}
static void
fm_directory_view_launch_application (GnomeVFSMimeApplication *application,
const char *uri,
FMDirectoryView *directory_view)
{
g_assert (application != NULL);
g_assert (uri != NULL);
g_assert (FM_IS_DIRECTORY_VIEW (directory_view));
nautilus_launch_application_parented
(application, uri, get_containing_window (directory_view));
}
static void
fm_directory_view_chose_application_callback (GnomeVFSMimeApplication *application,
gpointer callback_data)
{
ApplicationLaunchParameters *launch_parameters;
g_assert (callback_data != NULL);
launch_parameters = (ApplicationLaunchParameters *)callback_data;
g_assert (launch_parameters->application == NULL);
if (application != NULL) {
fm_directory_view_launch_application
(application, /* NOT the (empty) application in launch_parameters */
launch_parameters->uri,
launch_parameters->directory_view);
}
application_launch_parameters_free (launch_parameters);
}
static void
fm_directory_view_switch_location (FMDirectoryView *directory_view,
const char *new_uri,
gboolean use_new_window)
{
g_assert (FM_IS_DIRECTORY_VIEW (directory_view));
g_assert (new_uri != NULL);
if (use_new_window) {
nautilus_view_open_location_in_new_window
(directory_view->details->nautilus_view, new_uri, NULL);
} else {
nautilus_view_open_location
(directory_view->details->nautilus_view, new_uri);
}
}
static void
switch_location_and_view (NautilusViewIdentifier *identifier,
const char *new_uri,
FMDirectoryView *directory_view)
{
NautilusDirectory *directory;
NautilusFile *file;
g_assert (FM_IS_DIRECTORY_VIEW (directory_view));
g_assert (identifier != NULL);
g_assert (new_uri != NULL);
directory = nautilus_directory_get (new_uri);
file = nautilus_file_get (new_uri);
/* User has explicitly chosen a viewer other than the default, so
* make it the default and then switch locations.
*/
/* FIXME bugzilla.eazel.com 1053: We might want an atomic operation
* for switching location and viewer together, so we don't have to
* rely on metadata for holding the default location.
*/
nautilus_mime_set_default_component_for_uri (directory, file, identifier->iid);
nautilus_directory_unref (directory);
nautilus_file_unref (file);
fm_directory_view_switch_location
(directory_view, new_uri,
nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW, FALSE));
}
static void
fm_directory_view_chose_component_callback (NautilusViewIdentifier *identifier,
gpointer callback_data)
{
ViewerLaunchParameters *launch_parameters;
g_assert (callback_data != NULL);
launch_parameters = (ViewerLaunchParameters *)callback_data;
g_assert (launch_parameters->identifier == NULL);
if (identifier != NULL) {
switch_location_and_view (identifier, /* NOT the (empty) identifier in launch_parameters */
launch_parameters->uri,
launch_parameters->directory_view);
}
viewer_launch_parameters_free (launch_parameters);
}
static void
choose_program (FMDirectoryView *view,
NautilusFile *file,
GnomeVFSMimeActionType type)
{
char *uri;
g_assert (FM_IS_DIRECTORY_VIEW (view));
g_assert (NAUTILUS_IS_FILE (file));
g_assert (type == GNOME_VFS_MIME_ACTION_TYPE_COMPONENT ||
type == GNOME_VFS_MIME_ACTION_TYPE_APPLICATION);
nautilus_file_ref (file);
uri = nautilus_file_get_uri (file);
if (type == GNOME_VFS_MIME_ACTION_TYPE_COMPONENT) {
nautilus_choose_component_for_file
(file,
get_containing_window (view),
fm_directory_view_chose_component_callback,
viewer_launch_parameters_new
(NULL, uri, view));
} else {
nautilus_choose_application_for_file
(file,
get_containing_window (view),
fm_directory_view_chose_application_callback,
application_launch_parameters_new
(NULL, uri, view));
}
g_free (uri);
nautilus_file_unref (file);
}
static void
open_with_other_program (FMDirectoryView *view, GnomeVFSMimeActionType action_type)
{
GList *selection;
g_assert (FM_IS_DIRECTORY_VIEW (view));
g_assert (action_type == GNOME_VFS_MIME_ACTION_TYPE_APPLICATION ||
action_type == GNOME_VFS_MIME_ACTION_TYPE_COMPONENT);
selection = fm_directory_view_get_selection (view);
/* UI should have prevented this from being called unless exactly
* one item is selected. But we don't completely trust the UI, so
* we'll just complain rather than crashing.
*/
if (!nautilus_g_list_exactly_one_item (selection)) {
g_warning ("This shouldn't have been called with %d items selected",
g_list_length (selection));
}
choose_program (view, NAUTILUS_FILE (selection->data), action_type);
nautilus_file_list_free (selection);
}
/**
* Note that this is used both as a Bonobo menu callback and a signal callback.
* The first parameter is different in these cases, but we just ignore it anyway.
*/
static void
other_application_callback (gpointer ignored, gpointer callback_data)
{
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
open_with_other_program (FM_DIRECTORY_VIEW (callback_data),
GNOME_VFS_MIME_ACTION_TYPE_APPLICATION);
}
/**
* Note that this is used both as a Bonobo menu callback and a signal callback.
* The first parameter is different in these cases, but we just ignore it anyway.
*/
static void
other_viewer_callback (gpointer ignored, gpointer callback_data)
{
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
open_with_other_program (FM_DIRECTORY_VIEW (callback_data),
GNOME_VFS_MIME_ACTION_TYPE_COMPONENT);
}
/**
* Note that this is used both as a Bonobo menu callback and a signal callback.
* The first parameter is different in these cases, but we just ignore it anyway.
*/
static void
trash_callback (gpointer *ignored, gpointer callback_data)
{
FMDirectoryView *view;
GList *selection;
view = FM_DIRECTORY_VIEW (callback_data);
selection = fm_directory_view_get_selection (view);
if (selection_not_empty_in_menu_callback (view, selection)) {
fm_directory_view_trash_or_delete_files (view, selection);
}
nautilus_file_list_free (selection);
}
/**
* Note that this is used both as a Bonobo menu callback and a signal callback.
* The first parameter is different in these cases, but we just ignore it anyway.
*/
static void
duplicate_callback (gpointer *ignored, gpointer callback_data)
{
FMDirectoryView *view;
GList *selection;
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
view = FM_DIRECTORY_VIEW (callback_data);
selection = fm_directory_view_get_selection (view);
if (selection_not_empty_in_menu_callback (view, selection)) {
fm_directory_view_duplicate_selection (view, selection);
}
nautilus_file_list_free (selection);
}
/**
* Note that this is used both as a Bonobo menu callback and a signal callback.
* The first parameter is different in these cases, but we just ignore it anyway.
*/
static void
create_link_callback (gpointer ignored, gpointer callback_data)
{
FMDirectoryView *view;
GList *selection;
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
view = FM_DIRECTORY_VIEW (callback_data);
selection = fm_directory_view_get_selection (view);
if (selection_not_empty_in_menu_callback (view, selection)) {
fm_directory_view_create_links_for_files (view, selection);
}
nautilus_file_list_free (selection);
}
static void
bonobo_menu_select_all_callback (BonoboUIComponent *component,
gpointer callback_data,
const char *verb)
{
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
fm_directory_view_select_all (callback_data);
}
static void
bonobo_menu_empty_trash_callback (BonoboUIComponent *component,
gpointer callback_data,
const char *verb)
{
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
nautilus_file_operations_empty_trash (GTK_WIDGET (FM_DIRECTORY_VIEW (callback_data)));
}
/**
* Note that this is used both as a Bonobo menu callback and a signal callback.
* The first parameter is different in these cases, but we just ignore it anyway.
*/
static void
new_folder_callback (gpointer ignored, gpointer callback_data)
{
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
fm_directory_view_new_folder (FM_DIRECTORY_VIEW (callback_data));
}
/**
* Note that this is used both as a Bonobo menu callback and a signal callback.
* The first parameter is different in these cases, but we just ignore it anyway.
*/
static void
open_properties_window_callback (gpointer ignored, gpointer callback_data)
{
FMDirectoryView *view;
GList *selection;
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
view = FM_DIRECTORY_VIEW (callback_data);
selection = fm_directory_view_get_selection (view);
if (selection_not_empty_in_menu_callback (view, selection)) {
if (fm_directory_view_confirm_multiple_windows (view, g_list_length (selection))) {
g_list_foreach (selection, open_one_properties_window, view);
}
}
nautilus_file_list_free (selection);
}
static BonoboControl *
get_bonobo_control (FMDirectoryView *view)
{
return BONOBO_CONTROL (nautilus_view_get_bonobo_control
(view->details->nautilus_view));
}
static void
bonobo_control_activate_callback (BonoboObject *control, gboolean state, gpointer callback_data)
{
FMDirectoryView *view;
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
view = FM_DIRECTORY_VIEW (callback_data);
if (state) {
/* Add new menu items and perhaps whole menus */
fm_directory_view_merge_menus (view);
/* Set initial sensitivity, wording, toggle state, etc. */
fm_directory_view_update_menus (view);
}
/*
* Nothing to do on deactivate case, which never happens because
* of the way Nautilus content views are handled.
*/
}
/* Preferences changed callbacks */
static void
text_attribute_names_changed_callback (gpointer callback_data)
{
FMDirectoryView *view;
view = FM_DIRECTORY_VIEW (callback_data);
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
text_attribute_names_changed, (view));
}
/* FIXME bugzilla.eazel.com 1856:
* This #include and the call to nautilus_directory_async_state_changed
* are a hack to get the embedded text to appear if the preference started
* out off but gets turned on. This is obviously not the right API, but
* I wanted to check in and Darin was at lunch...
*/
#include <libnautilus-extensions/nautilus-directory-private.h>
static void
embedded_text_policy_changed_callback (gpointer callback_data)
{
FMDirectoryView *view;
view = FM_DIRECTORY_VIEW (callback_data);
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
embedded_text_policy_changed, (view));
nautilus_directory_async_state_changed
(fm_directory_view_get_model (view));
}
static void
image_display_policy_changed_callback (gpointer callback_data)
{
FMDirectoryView *view;
view = FM_DIRECTORY_VIEW (callback_data);
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
image_display_policy_changed, (view));
}
static void
directory_view_font_family_changed_callback (gpointer callback_data)
{
FMDirectoryView *view;
view = FM_DIRECTORY_VIEW (callback_data);
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
font_family_changed, (view));
}
static void
click_policy_changed_callback (gpointer callback_data)
{
FMDirectoryView *view;
view = FM_DIRECTORY_VIEW (callback_data);
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
click_policy_changed, (view));
}
static void
smooth_graphics_mode_changed_callback (gpointer callback_data)
{
FMDirectoryView *view;
view = FM_DIRECTORY_VIEW (callback_data);
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
smooth_graphics_mode_changed, (view));
}
static double fm_directory_view_preferred_zoom_levels[] = {
(double) NAUTILUS_ICON_SIZE_SMALLEST / NAUTILUS_ICON_SIZE_STANDARD,
(double) NAUTILUS_ICON_SIZE_SMALLER / NAUTILUS_ICON_SIZE_STANDARD,
(double) NAUTILUS_ICON_SIZE_SMALL / NAUTILUS_ICON_SIZE_STANDARD,
(double) NAUTILUS_ICON_SIZE_STANDARD / NAUTILUS_ICON_SIZE_STANDARD,
(double) NAUTILUS_ICON_SIZE_LARGE / NAUTILUS_ICON_SIZE_STANDARD,
(double) NAUTILUS_ICON_SIZE_LARGER / NAUTILUS_ICON_SIZE_STANDARD,
(double) NAUTILUS_ICON_SIZE_LARGEST / NAUTILUS_ICON_SIZE_STANDARD,
};
static void
fm_directory_view_initialize (FMDirectoryView *directory_view)
{
directory_view->details = g_new0 (FMDirectoryViewDetails, 1);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (directory_view),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_hadjustment (GTK_SCROLLED_WINDOW (directory_view), NULL);
gtk_scrolled_window_set_vadjustment (GTK_SCROLLED_WINDOW (directory_view), NULL);
directory_view->details->nautilus_view = nautilus_view_new (GTK_WIDGET (directory_view));
directory_view->details->zoomable = nautilus_zoomable_new_from_bonobo_control
(get_bonobo_control (directory_view),
.25,
4.0,
FALSE,
fm_directory_view_preferred_zoom_levels,
NAUTILUS_N_ELEMENTS (fm_directory_view_preferred_zoom_levels));
gtk_signal_connect (GTK_OBJECT (directory_view->details->nautilus_view),
"stop_loading",
GTK_SIGNAL_FUNC (stop_loading_callback),
directory_view);
gtk_signal_connect (GTK_OBJECT (directory_view->details->nautilus_view),
"load_location",
GTK_SIGNAL_FUNC (load_location_callback),
directory_view);
gtk_signal_connect (GTK_OBJECT (directory_view->details->nautilus_view),
"selection_changed",
GTK_SIGNAL_FUNC (selection_changed_callback),
directory_view);
gtk_signal_connect (GTK_OBJECT (get_bonobo_control (directory_view)),
"activate",
bonobo_control_activate_callback,
directory_view);
gtk_signal_connect (GTK_OBJECT (directory_view->details->zoomable),
"zoom_in",
zoomable_zoom_in_callback,
directory_view);
gtk_signal_connect (GTK_OBJECT (directory_view->details->zoomable),
"zoom_out",
zoomable_zoom_out_callback,
directory_view);
gtk_signal_connect (GTK_OBJECT (directory_view->details->zoomable),
"set_zoom_level",
zoomable_set_zoom_level_callback,
directory_view);
gtk_signal_connect (GTK_OBJECT (directory_view->details->zoomable),
"zoom_to_fit",
zoomable_zoom_to_fit_callback,
directory_view);
gtk_signal_connect_while_alive (GTK_OBJECT (nautilus_trash_monitor_get ()),
"trash_state_changed",
fm_directory_view_trash_state_changed_callback,
directory_view,
GTK_OBJECT (directory_view));
gtk_widget_show (GTK_WIDGET (directory_view));
/* Obtain the filtering preferences */
directory_view->details->show_hidden_files =
nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES, FALSE);
directory_view->details->show_backup_files =
nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES, FALSE);
/* Keep track of changes in this pref to filter files accordingly. */
nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
filtering_changed_callback,
directory_view);
/* Keep track of changes in this pref to filter files accordingly. */
nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES,
filtering_changed_callback,
directory_view);
/* Keep track of changes in this pref to display menu names correctly. */
nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_CONFIRM_TRASH,
schedule_update_menus_callback,
directory_view);
/* Keep track of changes in text attribute names */
nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_ICON_CAPTIONS,
text_attribute_names_changed_callback,
directory_view);
/* Keep track of changes in embedded text policy */
nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS,
embedded_text_policy_changed_callback,
directory_view);
/* Keep track of changes in image display policy */
nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
image_display_policy_changed_callback,
directory_view);
/* Keep track of changes in the font family */
nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
directory_view_font_family_changed_callback,
directory_view);
/* Keep track of changes in clicking policy */
nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_CLICK_POLICY,
click_policy_changed_callback,
directory_view);
/* Keep track of changes in graphics trade offs */
nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE,
smooth_graphics_mode_changed_callback,
directory_view);
}
static void
fm_directory_view_destroy (GtkObject *object)
{
FMDirectoryView *view;
view = FM_DIRECTORY_VIEW (object);
/* Since we are owned by the NautilusView, if we're going it's
* gone. It would be even better to NULL this out when the
* NautilusView goes away, but this is good enough for our
* purposes.
*/
view->details->nautilus_view = NULL;
nautilus_file_list_free (view->details->pending_files_added);
view->details->pending_files_added = NULL;
nautilus_file_list_free (view->details->pending_files_changed);
view->details->pending_files_changed = NULL;
nautilus_g_list_free_deep (view->details->pending_uris_selected);
view->details->pending_uris_selected = NULL;
fm_directory_view_stop (view);
fm_directory_view_clear (view);
disconnect_model_handlers (view);
nautilus_directory_unref (view->details->model);
if (view->details->display_selection_idle_id != 0) {
gtk_idle_remove (view->details->display_selection_idle_id);
}
if (view->details->update_menus_idle_id != 0) {
gtk_timeout_remove (view->details->update_menus_idle_id);
}
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
filtering_changed_callback,
view);
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES,
filtering_changed_callback,
view);
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_CONFIRM_TRASH,
schedule_update_menus_callback,
view);
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_ICON_CAPTIONS,
text_attribute_names_changed_callback,
view);
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS,
embedded_text_policy_changed_callback,
view);
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
image_display_policy_changed_callback,
view);
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
directory_view_font_family_changed_callback,
view);
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_CLICK_POLICY,
click_policy_changed_callback,
view);
nautilus_preferences_remove_callback (NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE,
smooth_graphics_mode_changed_callback,
view);
g_free (view->details);
NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object));
}
/**
* fm_directory_view_display_selection_info:
*
* Display information about the current selection, and notify the view frame of the changed selection.
* @view: FMDirectoryView for which to display selection info.
*
**/
void
fm_directory_view_display_selection_info (FMDirectoryView *view)
{
GList *selection;
GnomeVFSFileSize non_folder_size;
guint non_folder_count, folder_count, folder_item_count;
gboolean folder_item_count_known;
guint item_count;
GList *p;
char *first_item_name;
char *non_folder_str;
char *folder_count_str;
char *folder_item_count_str;
char *status_string;
NautilusFile *file;
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
selection = fm_directory_view_get_selection (view);
folder_item_count_known = TRUE;
folder_count = 0;
folder_item_count = 0;
non_folder_count = 0;
non_folder_size = 0;
first_item_name = NULL;
folder_count_str = NULL;
non_folder_str = NULL;
folder_item_count_str = NULL;
for (p = selection; p != NULL; p = p->next) {
file = p->data;
if (nautilus_file_is_directory (file)) {
folder_count++;
if (nautilus_file_get_directory_item_count (file, &item_count, NULL)) {
folder_item_count += item_count;
} else {
folder_item_count_known = FALSE;
}
} else {
non_folder_count++;
non_folder_size += nautilus_file_get_size (file);
}
if (first_item_name == NULL) {
first_item_name = nautilus_file_get_name (file);
}
}
nautilus_file_list_free (selection);
/* Break out cases for localization's sake. But note that there are still pieces
* being assembled in a particular order, which may be a problem for some localizers.
*/
if (folder_count != 0) {
if (folder_count == 1) {
if (non_folder_count == 0) {
folder_count_str = g_strdup_printf (_("\"%s\" selected"), first_item_name);
} else {
folder_count_str = g_strdup (_("1 folder selected"));
}
} else {
folder_count_str = g_strdup_printf (_("%d folders selected"), folder_count);
}
if (!folder_item_count_known) {
folder_item_count_str = g_strdup ("");
} else if (folder_item_count == 0) {
folder_item_count_str = g_strdup (_(" (containing 0 items)"));
} else if (folder_item_count == 1) {
folder_item_count_str = g_strdup (_(" (containing 1 item)"));
} else {
folder_item_count_str = g_strdup_printf (_(" (containing %d items)"), folder_item_count);
}
}
if (non_folder_count != 0) {
char *size_string;
size_string = gnome_vfs_format_file_size_for_display (non_folder_size);
if (folder_count == 0) {
if (non_folder_count == 1) {
non_folder_str = g_strdup_printf (_("\"%s\" selected (%s)"),
first_item_name,
size_string);
} else {
non_folder_str = g_strdup_printf (_("%d items selected (%s)"),
non_folder_count,
size_string);
}
} else {
/* Folders selected also, use "other" terminology */
if (non_folder_count == 1) {
non_folder_str = g_strdup_printf (_("1 other item selected (%s)"),
size_string);
} else {
non_folder_str = g_strdup_printf (_("%d other items selected (%s)"),
non_folder_count,
size_string);
}
}
g_free (size_string);
}
if (folder_count == 0 && non_folder_count == 0) {
status_string = g_strdup ("");
} else if (folder_count == 0) {
status_string = g_strdup (non_folder_str);
} else if (non_folder_count == 0) {
/* No use marking this for translation, since you
* can't reorder the strings, which is the main thing
* you'd want to do.
*/
status_string = g_strdup_printf ("%s%s",
folder_count_str,
folder_item_count_str);
} else {
/* This is marked for translation in case a localizer
* needs to change ", " to something else. The comma
* is between the message about the number of folders
* and the number of items in those folders and the
* message about the number of other items and the
* total size of those items.
*/
status_string = g_strdup_printf (_("%s%s, %s"),
folder_count_str,
folder_item_count_str,
non_folder_str);
}
g_free (first_item_name);
g_free (folder_count_str);
g_free (folder_item_count_str);
g_free (non_folder_str);
nautilus_view_report_status (view->details->nautilus_view,
status_string);
g_free (status_string);
}
static void
fm_directory_view_send_selection_change (FMDirectoryView *view)
{
GList *selection, *uris, *p;
/* Collect a list of URIs. */
selection = fm_directory_view_get_selection (view);
uris = NULL;
for (p = selection; p != NULL; p = p->next) {
uris = g_list_prepend (uris, nautilus_file_get_uri (p->data));
}
nautilus_file_list_free (selection);
/* Send the selection change. */
nautilus_view_report_selection_change (view->details->nautilus_view,
uris);
/* Free the URIs. */
nautilus_g_list_free_deep (uris);
}
static void
load_location_callback (NautilusView *nautilus_view,
const char *location,
FMDirectoryView *directory_view)
{
fm_directory_view_load_uri (directory_view, location);
}
static void
selection_changed_callback (NautilusView *nautilus_view,
GList *selection_uris,
FMDirectoryView *directory_view)
{
GList *selection, *p;
NautilusFile *file;
selection = NULL;
if (directory_view->details->loading) {
nautilus_g_list_free_deep (directory_view->details->pending_uris_selected);
directory_view->details->pending_uris_selected = NULL;
}
if (!directory_view->details->loading) {
/* If we aren't still loading, set the selection right now. */
for (p = selection_uris; p != NULL; p = p->next) {
file = nautilus_file_get (p->data);
if (file != NULL) {
selection = g_list_prepend (selection, file);
}
}
fm_directory_view_set_selection (directory_view, selection);
nautilus_file_list_free (selection);
} else {
/* If we are still loading, add to the list of pending URIs instead. */
for (p = selection_uris; p != NULL; p = p->next) {
directory_view->details->pending_uris_selected =
g_list_prepend (directory_view->details->pending_uris_selected,
g_strdup (p->data));
}
}
}
static void
stop_loading_callback (NautilusView *nautilus_view,
FMDirectoryView *directory_view)
{
fm_directory_view_stop (directory_view);
}
static void
done_loading (FMDirectoryView *view)
{
if (!view->details->loading) {
return;
}
/* This can be called during destruction, in which case there
* is no NautilusView any more.
*/
if (view->details->nautilus_view != NULL) {
nautilus_view_report_load_complete (view->details->nautilus_view);
schedule_update_menus (view);
}
view->details->loading = FALSE;
}
/**
* Note that this is used both as a Bonobo menu callback and a signal callback.
* The first parameter is different in these cases, but we just ignore it anyway.
*/
static void
reset_background_callback (gpointer ignored, gpointer callback_data)
{
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
nautilus_background_reset
(fm_directory_view_get_background
(FM_DIRECTORY_VIEW (callback_data)));
}
/* handle the zoom in/out menu items */
static void
zoom_in_callback (GtkMenuItem *item, FMDirectoryView *directory_view)
{
fm_directory_view_bump_zoom_level (directory_view, 1);
}
static void
zoom_out_callback (GtkMenuItem *item, FMDirectoryView *directory_view)
{
fm_directory_view_bump_zoom_level (directory_view, -1);
}
static void
zoom_default_callback (GtkMenuItem *item, FMDirectoryView *directory_view)
{
fm_directory_view_restore_default_zoom_level (directory_view);
}
static void
zoomable_zoom_in_callback (NautilusZoomable *zoomable, FMDirectoryView *directory_view)
{
fm_directory_view_bump_zoom_level (directory_view, 1);
}
static void
zoomable_zoom_out_callback (NautilusZoomable *zoomable, FMDirectoryView *directory_view)
{
fm_directory_view_bump_zoom_level (directory_view, -1);
}
static NautilusZoomLevel
nautilus_zoom_level_from_double(double zoom_level)
{
int icon_size = floor(zoom_level * NAUTILUS_ICON_SIZE_STANDARD + 0.5);
if (icon_size <= NAUTILUS_ICON_SIZE_SMALLEST) {
return NAUTILUS_ZOOM_LEVEL_SMALLEST;
} else if (icon_size <= NAUTILUS_ICON_SIZE_SMALLER) {
return NAUTILUS_ZOOM_LEVEL_SMALLER;
} else if (icon_size <= NAUTILUS_ICON_SIZE_SMALL) {
return NAUTILUS_ZOOM_LEVEL_SMALL;
} else if (icon_size <= NAUTILUS_ICON_SIZE_STANDARD) {
return NAUTILUS_ZOOM_LEVEL_STANDARD;
} else if (icon_size <= NAUTILUS_ICON_SIZE_LARGE) {
return NAUTILUS_ZOOM_LEVEL_LARGE;
} else if (icon_size <= NAUTILUS_ICON_SIZE_LARGER) {
return NAUTILUS_ZOOM_LEVEL_LARGER;
} else {
return NAUTILUS_ZOOM_LEVEL_LARGEST;
}
}
static void
zoomable_set_zoom_level_callback (NautilusZoomable *zoomable, double level, FMDirectoryView *view)
{
fm_directory_view_zoom_to_level (view, nautilus_zoom_level_from_double(level));
}
static void
zoomable_zoom_to_fit_callback (NautilusZoomable *zoomable, FMDirectoryView *view)
{
/* FIXME bugzilla.eazel.com 2388:
* Need to really implement "zoom to fit"
*/
fm_directory_view_restore_default_zoom_level (view);
}
static gboolean
display_pending_files (FMDirectoryView *view)
{
GList *files_added, *files_changed, *uris_selected, *p;
NautilusFile *file;
GList *selection;
char *uri;
selection = NULL;
if (view->details->model != NULL
&& nautilus_directory_are_all_files_seen (view->details->model)) {
done_loading (view);
}
files_added = view->details->pending_files_added;
files_changed = view->details->pending_files_changed;
uris_selected = view->details->pending_uris_selected;
if (files_added == NULL && files_changed == NULL && uris_selected == NULL) {
return FALSE;
}
view->details->pending_files_added = NULL;
view->details->pending_files_changed = NULL;
gtk_signal_emit (GTK_OBJECT (view), signals[BEGIN_ADDING_FILES]);
for (p = files_added; p != NULL; p = p->next) {
file = p->data;
if (nautilus_directory_contains_file (view->details->model, file)) {
gtk_signal_emit (GTK_OBJECT (view),
signals[ADD_FILE],
file);
}
}
for (p = files_changed; p != NULL; p = p->next) {
file = p->data;
gtk_signal_emit (GTK_OBJECT (view),
signals[FILE_CHANGED],
file);
}
gtk_signal_emit (GTK_OBJECT (view), signals[DONE_ADDING_FILES]);
nautilus_file_list_free (files_added);
nautilus_file_list_free (files_changed);
if (nautilus_directory_are_all_files_seen (view->details->model)
&& uris_selected != NULL) {
view->details->pending_uris_selected = NULL;
for (p = uris_selected; p != NULL; p = p->next) {
uri = p->data;
file = nautilus_file_get (uri);
selection = g_list_prepend (selection, file);
}
nautilus_g_list_free_deep (uris_selected);
fm_directory_view_set_selection (view, selection);
fm_directory_view_reveal_selection (view);
nautilus_file_list_free (selection);
}
return TRUE;
}
static gboolean
display_selection_info_idle_callback (gpointer data)
{
FMDirectoryView *view;
view = FM_DIRECTORY_VIEW (data);
view->details->display_selection_idle_id = 0;
fm_directory_view_display_selection_info (view);
fm_directory_view_send_selection_change (view);
return FALSE;
}
static gboolean
update_menus_idle_callback (gpointer data)
{
FMDirectoryView *view;
view = FM_DIRECTORY_VIEW (data);
fm_directory_view_update_menus (view);
view->details->update_menus_idle_id = 0;
return FALSE;
}
static gboolean
display_pending_idle_callback (gpointer data)
{
/* Don't do another idle until we receive more files. */
FMDirectoryView *view;
view = FM_DIRECTORY_VIEW (data);
view->details->display_pending_idle_id = 0;
display_pending_files (view);
return FALSE;
}
static gboolean
display_pending_timeout_callback (gpointer data)
{
/* Do another timeout if we displayed some files.
* Once we get all the files, we'll start using
* idle instead.
*/
FMDirectoryView *view;
gboolean displayed_some;
view = FM_DIRECTORY_VIEW (data);
displayed_some = display_pending_files (view);
if (displayed_some) {
return TRUE;
}
view->details->display_pending_timeout_id = 0;
return FALSE;
}
static void
schedule_idle_display_of_pending_files (FMDirectoryView *view)
{
/* No need to schedule an idle if there's already one pending. */
if (view->details->display_pending_idle_id != 0) {
return;
}
/* An idle takes precedence over a timeout. */
unschedule_timeout_display_of_pending_files (view);
view->details->display_pending_idle_id =
gtk_idle_add (display_pending_idle_callback, view);
}
static void
schedule_timeout_display_of_pending_files (FMDirectoryView *view)
{
/* No need to schedule a timeout if there's already one pending. */
if (view->details->display_pending_timeout_id != 0) {
return;
}
/* An idle takes precedence over a timeout. */
if (view->details->display_pending_idle_id != 0) {
return;
}
view->details->display_pending_timeout_id =
gtk_timeout_add (DISPLAY_TIMEOUT_INTERVAL_MSECS,
display_pending_timeout_callback, view);
}
static void
unschedule_idle_display_of_pending_files (FMDirectoryView *view)
{
/* Get rid of idle if it's active. */
if (view->details->display_pending_idle_id != 0) {
g_assert (view->details->display_pending_timeout_id == 0);
gtk_idle_remove (view->details->display_pending_idle_id);
view->details->display_pending_idle_id = 0;
}
}
static void
unschedule_timeout_display_of_pending_files (FMDirectoryView *view)
{
/* Get rid of timeout if it's active. */
if (view->details->display_pending_timeout_id != 0) {
g_assert (view->details->display_pending_idle_id == 0);
gtk_timeout_remove (view->details->display_pending_timeout_id);
view->details->display_pending_timeout_id = 0;
}
}
static void
unschedule_display_of_pending_files (FMDirectoryView *view)
{
unschedule_idle_display_of_pending_files (view);
unschedule_timeout_display_of_pending_files (view);
}
static void
queue_pending_files (FMDirectoryView *view,
GList *files,
GList **pending_list)
{
GList *filtered_files;
GList *files_iterator;
NautilusFile *file;
char * name;
gboolean include_file;
/* Desktop always filters out hidden files */
if (FM_IS_DESKTOP_ICON_VIEW (view)) {
view->details->show_hidden_files = FALSE;
view->details->show_backup_files = FALSE;
}
filtered_files = NULL;
/* Filter out hidden files if needed */
if (!view->details->show_hidden_files || !view->details->show_backup_files) {
/* FIXME bugzilla.eazel.com 653:
* Eventually this should become a generic filtering thingy.
*/
for (files_iterator = files;
files_iterator != NULL;
files_iterator = files_iterator->next) {
file = NAUTILUS_FILE (files_iterator->data);
g_assert (file != NULL);
name = nautilus_file_get_name (file);
g_assert (name != NULL);
if (!view->details->show_hidden_files && nautilus_str_has_prefix (name, ".")) {
include_file = FALSE;
} else if (!view->details->show_backup_files && nautilus_str_has_suffix (name, "~")) {
include_file = FALSE;
} else {
include_file = TRUE;
}
if (include_file) {
filtered_files = g_list_append (filtered_files, file);
}
g_free (name);
}
files = filtered_files;
}
/* Put the files on the pending list if there are any. */
if (files != NULL) {
nautilus_file_list_ref (files);
*pending_list = g_list_concat (*pending_list, g_list_copy (files));
/* If we haven't see all the files yet, then we'll wait for the
* timeout to fire. If we have seen all the files, then we'll use
* an idle instead.
*/
if (nautilus_directory_are_all_files_seen (view->details->model)) {
schedule_idle_display_of_pending_files (view);
} else {
schedule_timeout_display_of_pending_files (view);
}
}
g_list_free (filtered_files);
}
static void
files_added_callback (NautilusDirectory *directory,
GList *files,
gpointer callback_data)
{
FMDirectoryView *view;
view = FM_DIRECTORY_VIEW (callback_data);
queue_pending_files (view, files, &view->details->pending_files_added);
}
static void
files_changed_callback (NautilusDirectory *directory,
GList *files,
gpointer callback_data)
{
FMDirectoryView *view;
view = FM_DIRECTORY_VIEW (callback_data);
queue_pending_files (view, files, &view->details->pending_files_changed);
}
/**
* fm_directory_queue_notice_file_change
*
* Called by a subclass to put a file into the queue of files to update.
* This is only necessary when the subclass is monitoring files other than
* the ones in the directory for this location.
*/
void
fm_directory_view_queue_file_change (FMDirectoryView *view, NautilusFile *file)
{
GList *singleton_list;
singleton_list = g_list_prepend (NULL, file);
queue_pending_files (view, singleton_list, &view->details->pending_files_changed);
g_list_free (singleton_list);
}
/**
* fm_directory_view_clear:
*
* Emit the signal to clear the contents of the view. Subclasses must
* override the signal handler for this signal. This is normally called
* only by FMDirectoryView.
* @view: FMDirectoryView to empty.
*
**/
void
fm_directory_view_clear (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
gtk_signal_emit (GTK_OBJECT (view), signals[CLEAR]);
}
/**
* fm_directory_view_begin_loading:
*
* Emit the signal to prepare for loading the contents of a new location.
* Subclasses might want to override the signal handler for this signal.
* This is normally called only by FMDirectoryView.
* @view: FMDirectoryView that is switching to view a new location.
*
**/
void
fm_directory_view_begin_loading (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
gtk_signal_emit (GTK_OBJECT (view), signals[BEGIN_LOADING]);
}
/**
* fm_directory_view_bump_zoom_level:
*
* bump the current zoom level by invoking the relevant subclass through the slot
*
**/
void
fm_directory_view_bump_zoom_level (FMDirectoryView *view, int zoom_increment)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
if (!fm_directory_view_supports_zooming (view)) {
return;
}
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
bump_zoom_level, (view, zoom_increment));
}
/**
* fm_directory_view_zoom_to_level:
*
* Set the current zoom level by invoking the relevant subclass through the slot
*
**/
void
fm_directory_view_zoom_to_level (FMDirectoryView *view, int zoom_level)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
if (!fm_directory_view_supports_zooming (view)) {
return;
}
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
zoom_to_level, (view, zoom_level));
}
void
fm_directory_view_set_zoom_level (FMDirectoryView *view, int zoom_level)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
if (!fm_directory_view_supports_zooming (view)) {
return;
}
nautilus_zoomable_set_zoom_level
(view->details->zoomable,
(double) nautilus_get_icon_size_for_zoom_level (zoom_level)
/ NAUTILUS_ICON_SIZE_STANDARD);
}
/**
* fm_directory_view_restore_default_zoom_level:
*
* restore to the default zoom level by invoking the relevant subclass through the slot
*
**/
void
fm_directory_view_restore_default_zoom_level (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
if (!fm_directory_view_supports_zooming (view)) {
return;
}
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
restore_default_zoom_level, (view));
}
/**
* fm_directory_view_can_zoom_in:
*
* Determine whether the view can be zoomed any closer.
* @view: The zoomable FMDirectoryView.
*
* Return value: TRUE if @view can be zoomed any closer, FALSE otherwise.
*
**/
gboolean
fm_directory_view_can_zoom_in (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
if (!fm_directory_view_supports_zooming (view)) {
return FALSE;
}
return NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
can_zoom_in, (view));
}
/**
* fm_directory_view_can_zoom_out:
*
* Determine whether the view can be zoomed any further away.
* @view: The zoomable FMDirectoryView.
*
* Return value: TRUE if @view can be zoomed any further away, FALSE otherwise.
*
**/
gboolean
fm_directory_view_can_zoom_out (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
if (!fm_directory_view_supports_zooming (view)) {
return FALSE;
}
return NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
can_zoom_out, (view));
}
GtkWidget *
fm_directory_view_get_background_widget (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), NULL);
return NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
get_background_widget, (view));
}
NautilusBackground *
fm_directory_view_get_background (FMDirectoryView *view)
{
return nautilus_get_widget_background (fm_directory_view_get_background_widget (view));
}
/**
* fm_directory_view_get_selection:
*
* Get a list of NautilusFile pointers that represents the
* currently-selected items in this view. Subclasses must override
* the signal handler for the 'get_selection' signal. Callers are
* responsible for g_free-ing the list (but not its data).
* @view: FMDirectoryView whose selected items are of interest.
*
* Return value: GList of NautilusFile pointers representing the selection.
*
**/
GList *
fm_directory_view_get_selection (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), NULL);
return NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
get_selection, (view));
}
/**
* fm_directory_view_get_bonobo_ui_container:
*
* Get the BonoboUIContainer for this FMDirectoryView.
* This is normally called only by subclasses in order to
* install and modify bonobo menus and such.
* @view: FMDirectoryView of interest.
*
* Return value: BonoboUIContainer for this view.
*
**/
Bonobo_UIContainer
fm_directory_view_get_bonobo_ui_container (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), NULL);
return bonobo_control_get_remote_ui_container (get_bonobo_control (view));
}
/**
* fm_directory_view_get_nautilus_view:
*
* Get the NautilusView for this FMDirectoryView.
* This is normally called only by the embedding framework.
* @view: FMDirectoryView of interest.
*
* Return value: NautilusView for this view.
*
**/
NautilusView *
fm_directory_view_get_nautilus_view (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), NULL);
return view->details->nautilus_view;
}
/**
* fm_directory_view_get_model:
*
* Get the model for this FMDirectoryView.
* @view: FMDirectoryView of interest.
*
* Return value: NautilusDirectory for this view.
*
**/
NautilusDirectory *
fm_directory_view_get_model (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), NULL);
return view->details->model;
}
static void
append_uri_one (gpointer data, gpointer callback_data)
{
NautilusFile *file;
GList **result;
g_assert (NAUTILUS_IS_FILE (data));
g_assert (callback_data != NULL);
result = (GList **) callback_data;
file = (NautilusFile *) data;
*result = g_list_append (*result, nautilus_file_get_uri (file));
}
static void
fm_directory_view_create_links_for_files (FMDirectoryView *view, GList *files)
{
GList *uris;
g_assert (FM_IS_DIRECTORY_VIEW (view));
g_assert (files != NULL);
/* create a list of URIs */
uris = NULL;
g_list_foreach (files, append_uri_one, &uris);
g_assert (g_list_length (uris) == g_list_length (files));
nautilus_file_operations_copy_move (uris, NULL, NULL, GDK_ACTION_LINK, GTK_WIDGET (view));
nautilus_g_list_free_deep (uris);
}
static void
fm_directory_view_duplicate_selection (FMDirectoryView *view, GList *files)
{
GList *uris;
g_assert (FM_IS_DIRECTORY_VIEW (view));
g_assert (files != NULL);
/* create a list of URIs */
uris = NULL;
g_list_foreach (files, append_uri_one, &uris);
g_assert (g_list_length (uris) == g_list_length (files));
nautilus_file_operations_copy_move (uris, NULL, NULL, GDK_ACTION_COPY, GTK_WIDGET (view));
nautilus_g_list_free_deep (uris);
}
static gboolean
all_files_in_trash (GList *files)
{
GList *node;
/* Result is ambiguous if called on NULL, so disallow. */
g_return_val_if_fail (files != NULL, FALSE);
for (node = files; node != NULL; node = node->next) {
if (!nautilus_file_is_in_trash (NAUTILUS_FILE (node->data))) {
return FALSE;
}
}
return TRUE;
}
static gboolean
fm_directory_all_selected_items_in_trash (FMDirectoryView *view)
{
GList *selection;
gboolean result;
/* If the contents share a parent directory, we need only
* check that parent directory. Otherwise we have to inspect
* each selected item.
*/
selection = fm_directory_view_get_selection (view);
result = (selection == NULL) ? FALSE : all_files_in_trash (selection);
nautilus_file_list_free (selection);
return result;
}
gboolean
fm_directory_link_type_in_selection (FMDirectoryView *view, NautilusLinkType link_type)
{
gboolean saw_link;
GList *selection, *node;
NautilusFile *file;
char *uri, *path;
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
saw_link = FALSE;
selection = fm_directory_view_get_selection (FM_DIRECTORY_VIEW (view));
for (node = selection; node != NULL; node = node->next) {
file = NAUTILUS_FILE (selection->data);
if (!nautilus_file_is_nautilus_link (file)) {
continue;
}
uri = nautilus_file_get_uri (file);
path = gnome_vfs_get_local_path_from_uri (uri);
switch (link_type) {
case NAUTILUS_LINK_TRASH:
/* It's probably OK that this ignores trash links that
* are not local since the trash link we care about is
* on the desktop.
*/
saw_link = path != NULL && nautilus_link_local_is_trash_link (path);
if (saw_link) {
break;
}
break;
case NAUTILUS_LINK_MOUNT:
saw_link = path != NULL && nautilus_link_local_is_volume_link (path);
if (saw_link) {
break;
}
break;
case NAUTILUS_LINK_HOME:
saw_link = path != NULL && nautilus_link_local_is_home_link (path);
if (saw_link) {
break;
}
break;
default:
break;
}
g_free (path);
g_free (uri);
}
nautilus_file_list_free (selection);
return saw_link;
}
/* special_link_in_selection
*
* Return TRUE is one of our special links is the selection.
* Special links include the following:
* NAUTILUS_LINK_TRASH, NAUTILUS_LINK_HOME, NAUTILUS_LINK_MOUNT
*/
static gboolean
special_link_in_selection (FMDirectoryView *view)
{
if (fm_directory_link_type_in_selection (view, NAUTILUS_LINK_TRASH)) {
return TRUE;
}
if (fm_directory_link_type_in_selection (view, NAUTILUS_LINK_HOME)) {
return TRUE;
}
if (fm_directory_link_type_in_selection (view, NAUTILUS_LINK_MOUNT)) {
return TRUE;
}
return FALSE;
}
static gboolean
fm_directory_view_can_move_file_to_trash (FMDirectoryView *view, NautilusFile *file)
{
/* Return TRUE if we can get a trash directory on the same volume as this file. */
char *directory;
GnomeVFSURI *directory_uri;
GnomeVFSURI *trash_dir_uri;
gboolean result;
directory = nautilus_file_get_parent_uri (file);
if (directory == NULL) {
return FALSE;
}
directory_uri = gnome_vfs_uri_new (directory);
result = gnome_vfs_find_directory (directory_uri, GNOME_VFS_DIRECTORY_KIND_TRASH,
&trash_dir_uri, FALSE, FALSE, 0777) == GNOME_VFS_OK;
if (result) {
if (gnome_vfs_uri_equal (trash_dir_uri, directory_uri)
|| gnome_vfs_uri_is_parent (trash_dir_uri, directory_uri, TRUE)) {
/* don't allow trashing items already in the Trash */
result = FALSE;
}
gnome_vfs_uri_unref (trash_dir_uri);
}
gnome_vfs_uri_unref (directory_uri);
g_free (directory);
return result;
}
static char *
file_name_from_uri (const char *uri)
{
NautilusFile *file;
char *file_name;
file = nautilus_file_get (uri);
file_name = nautilus_file_get_name (file);
nautilus_file_unref (file);
return file_name;
}
static gboolean
fm_directory_view_confirm_deletion (FMDirectoryView *view, GList *uris, gboolean all)
{
GnomeDialog *dialog;
char *prompt;
int uri_count;
char *file_name;
g_assert (FM_IS_DIRECTORY_VIEW (view));
uri_count = g_list_length (uris);
g_assert (uri_count > 0);
if (uri_count == 1) {
file_name = file_name_from_uri ((char *)uris->data);
prompt = g_strdup_printf (_("\"%s\" cannot be moved to the trash. Do "
"you want to delete it immediately?"), file_name);
g_free (file_name);
} else {
if (all) {
prompt = g_strdup_printf (_("The %d selected items cannot be moved "
"to the trash. Do you want to delete them "
"immediately?"), uri_count);
} else {
prompt = g_strdup_printf (_("%d of the selected items cannot be moved "
"to the trash. Do you want to delete those "
"%d items immediately?"), uri_count, uri_count);
}
}
dialog = nautilus_yes_no_dialog (
prompt,
_("Delete Immediately?"),
_("Delete"),
GNOME_STOCK_BUTTON_CANCEL,
get_containing_window (view));
g_free (prompt);
return gnome_dialog_run (dialog) == GNOME_OK;
}
static gboolean
confirm_delete_from_trash (FMDirectoryView *view, GList *uris)
{
GnomeDialog *dialog;
char *prompt;
char *file_name;
int uri_count;
g_assert (FM_IS_DIRECTORY_VIEW (view));
/* Just Say Yes if the preference says not to confirm. */
if (!nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_CONFIRM_TRASH, TRUE)) {
return TRUE;
}
uri_count = g_list_length (uris);
g_assert (uri_count > 0);
if (uri_count == 1) {
file_name = file_name_from_uri ((char *)uris->data);
prompt = g_strdup_printf (_("Are you sure you want to permanently delete \"%s\" "
"from the trash?"), file_name);
g_free (file_name);
} else {
prompt = g_strdup_printf (_("Are you sure you want to permanently delete "
"the %d selected items from the trash?"), uri_count);
}
dialog = nautilus_yes_no_dialog (
prompt,
_("Delete From Trash?"),
_("Delete"),
GNOME_STOCK_BUTTON_CANCEL,
get_containing_window (view));
g_free (prompt);
return gnome_dialog_run (dialog) == GNOME_OK;
}
static void
fm_directory_view_trash_or_delete_files (FMDirectoryView *view, GList *files)
{
GList *file_node;
NautilusFile *file;
char *file_uri;
GList *moveable_uris;
GList *unmoveable_uris;
GList *in_trash_uris;
g_assert (FM_IS_DIRECTORY_VIEW (view));
g_assert (files != NULL);
/* Collect three lists: (1) items that can be moved to trash,
* (2) items that can only be deleted in place, and (3) items that
* are already in trash.
*
* Always move (1) to trash if non-empty.
* Delete (3) only if (1) and (2) are non-empty, otherwise ignore (3).
* Ask before deleting (2) if non-empty.
*/
moveable_uris = NULL;
unmoveable_uris = NULL;
in_trash_uris = NULL;
for (file_node = files; file_node != NULL; file_node = file_node->next) {
file = NAUTILUS_FILE (file_node->data);
file_uri = nautilus_file_get_uri (file);
if (fm_directory_view_can_move_file_to_trash (view, file)) {
moveable_uris = g_list_prepend (moveable_uris, file_uri);
} else if (nautilus_file_is_in_trash (file)) {
in_trash_uris = g_list_prepend (in_trash_uris, file_uri);
} else {
unmoveable_uris = g_list_prepend (unmoveable_uris, file_uri);
}
}
if (moveable_uris != NULL) {
nautilus_file_operations_move_to_trash (moveable_uris, GTK_WIDGET (view));
}
if (in_trash_uris != NULL && moveable_uris == NULL && unmoveable_uris == NULL) {
/* Don't confirm if the preference says not to. */
if (confirm_delete_from_trash (view, in_trash_uris)) {
nautilus_file_operations_delete (in_trash_uris, GTK_WIDGET (view));
}
}
if (unmoveable_uris != NULL) {
if (fm_directory_view_confirm_deletion (view,
unmoveable_uris,
moveable_uris == NULL)) {
nautilus_file_operations_delete (unmoveable_uris, GTK_WIDGET (view));
}
}
nautilus_g_list_free_deep (moveable_uris);
nautilus_g_list_free_deep (unmoveable_uris);
nautilus_g_list_free_deep (in_trash_uris);
}
static void
start_renaming_item (FMDirectoryView *view, const char *uri)
{
GList *selection;
NautilusFile *file;
selection = NULL;
file = nautilus_file_get (uri);
if (file == NULL) {
return;
}
selection = g_list_prepend (NULL, file);
fm_directory_view_set_selection (view, selection);
nautilus_file_list_free (selection);
}
typedef struct {
FMDirectoryView *view;
char *uri;
} RenameLaterParameters;
static gboolean
new_folder_rename_later (void *callback_data)
{
RenameLaterParameters *parameters;
parameters = callback_data;
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, parameters->view,
start_renaming_item, (parameters->view, parameters->uri));
g_free (parameters->uri);
g_free (parameters);
return FALSE;
}
static void
new_folder_done (const char *new_folder_uri, gpointer data)
{
FMDirectoryView *directory_view;
RenameLaterParameters *parameters;
directory_view = (FMDirectoryView *)data;
parameters = g_new0 (RenameLaterParameters, 1);
parameters->uri = g_strdup (new_folder_uri);
parameters->view = directory_view;
/* FIXME bugzilla.eazel.com 1260:
* runing the start_renaming_item with a delay because at this point
* it's not in the icon container's icon list.
* There are two problems with this besides clunkiness - by the time the
* timeout expires, the directory view could be dead and the delay value
* is arbitrary, if the machine is loaded up, it may not be enough.
* Need to add a mechanism here that ensures synchronously that the item
* is added to the icon container instead.
*/
gtk_timeout_add (100, new_folder_rename_later, parameters);
}
void
fm_directory_view_new_folder (FMDirectoryView *directory_view)
{
char *parent_uri;
parent_uri = fm_directory_view_get_uri (directory_view);
nautilus_file_operations_new_folder (GTK_WIDGET(directory_view), parent_uri, new_folder_done, directory_view);
g_free (parent_uri);
}
/* handle the open command */
static void
open_one_in_new_window (gpointer data, gpointer callback_data)
{
g_assert (NAUTILUS_IS_FILE (data));
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
fm_directory_view_activate_file (FM_DIRECTORY_VIEW (callback_data), NAUTILUS_FILE (data), TRUE);
}
static void
open_one_properties_window (gpointer data, gpointer callback_data)
{
g_assert (NAUTILUS_IS_FILE (data));
g_assert (FM_IS_DIRECTORY_VIEW (callback_data));
fm_properties_window_present (data, callback_data);
}
static void
remove_custom_icon (gpointer file, gpointer callback_data)
{
g_assert (NAUTILUS_IS_FILE (file));
g_assert (callback_data == NULL);
nautilus_file_set_metadata (NAUTILUS_FILE (file),
NAUTILUS_METADATA_KEY_ICON_SCALE,
NULL, NULL);
nautilus_file_set_metadata (NAUTILUS_FILE (file),
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL, NULL);
}
static NautilusFile *
get_directory_as_file (FMDirectoryView *view)
{
g_assert (FM_IS_DIRECTORY_VIEW (view));
return nautilus_directory_get_corresponding_file
(fm_directory_view_get_model (view));
}
static gboolean
files_have_any_custom_images (GList *files)
{
GList *p;
char *uri;
for (p = files; p != NULL; p = p->next) {
uri = nautilus_file_get_metadata (NAUTILUS_FILE (p->data),
NAUTILUS_METADATA_KEY_CUSTOM_ICON,
NULL);
if (uri != NULL) {
g_free (uri);
return TRUE;
}
}
return FALSE;
}
/**
* Note that this is used both as a Bonobo menu callback and a signal callback.
* The first parameter is different in these cases, but we just ignore it anyway.
*/
static void
remove_custom_icons_callback (gpointer ignored, gpointer view)
{
GList *selection;
selection = fm_directory_view_get_selection (FM_DIRECTORY_VIEW (view));
g_list_foreach (selection, remove_custom_icon, NULL);
nautilus_file_list_free (selection);
/* Update menus because Remove Custom Icons item has changed state */
schedule_update_menus (FM_DIRECTORY_VIEW (view));
}
static void
finish_inserting_menu_item (GtkMenu *menu,
GtkWidget *menu_item,
int position,
gboolean sensitive)
{
gtk_widget_set_sensitive (menu_item, sensitive);
gtk_widget_show (menu_item);
gtk_menu_insert (menu, menu_item, position);
}
static void
finish_appending_menu_item (GtkMenu *menu, GtkWidget *menu_item, gboolean sensitive)
{
finish_inserting_menu_item (menu, menu_item, -1, sensitive);
}
static void
compute_menu_item_info (FMDirectoryView *directory_view,
const char *path,
GList *selection,
gboolean include_accelerator_underbars,
char **return_name,
gboolean *return_sensitivity)
{
char *name, *stripped;
int count;
*return_sensitivity = TRUE;
if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_OPEN) == 0) {
name = g_strdup (_("_Open"));
*return_sensitivity = nautilus_g_list_exactly_one_item (selection);
} else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_OPEN_WITH) == 0) {
name = g_strdup (_("Open With"));
*return_sensitivity = nautilus_g_list_exactly_one_item (selection);
} else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_OTHER_APPLICATION) == 0) {
name = g_strdup (_("Other Application..."));
} else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_OTHER_VIEWER) == 0) {
name = g_strdup (_("Other Viewer..."));
} else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_OPEN_IN_NEW_WINDOW) == 0) {
count = g_list_length (selection);
if (count <= 1) {
name = g_strdup (_("Open in _New Window"));
} else {
name = g_strdup_printf (_("Open in %d _New Windows"), count);
}
if (nautilus_g_list_exactly_one_item (selection)) {
/* If the only selected item is launchable, dim out "Open in New Window"
* to avoid confusion about how it differs from "Open" in this case (it
* doesn't differ; they would do the same thing).
*/
*return_sensitivity = !file_is_launchable (NAUTILUS_FILE (selection->data));
} else {
*return_sensitivity = selection != NULL;
}
} else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_NEW_FOLDER) == 0) {
name = g_strdup (_("New Folder"));
*return_sensitivity = fm_directory_view_supports_creating_files (directory_view);
} else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_TRASH) == 0) {
if (fm_directory_all_selected_items_in_trash (directory_view)) {
if (nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_CONFIRM_TRASH, TRUE)) {
name = g_strdup (_("Delete from _Trash..."));
} else {
name = g_strdup (_("Delete from _Trash"));
}
} else {
name = g_strdup (_("Move to _Trash"));
}
*return_sensitivity = !fm_directory_view_is_read_only (directory_view) && selection != NULL;
} else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_DUPLICATE) == 0) {
name = g_strdup (_("_Duplicate"));
*return_sensitivity = fm_directory_view_supports_creating_files (directory_view) && selection != NULL;
} else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_CREATE_LINK) == 0) {
if (selection != NULL && !nautilus_g_list_exactly_one_item (selection)) {
name = g_strdup (_("Create _Links"));
} else {
name = g_strdup (_("Create _Link"));
}
*return_sensitivity = fm_directory_view_supports_creating_files (directory_view) && selection != NULL;
} else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_SHOW_PROPERTIES) == 0) {
/* No ellipses here because this command does not require further
* information to be completed.
*/
name = g_strdup (_("Show _Properties"));
*return_sensitivity = selection != NULL && fm_directory_view_supports_properties (directory_view);
} else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_EMPTY_TRASH) == 0) {
if (nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_CONFIRM_TRASH, TRUE)) {
name = g_strdup (_("_Empty Trash..."));
} else {
name = g_strdup (_("_Empty Trash"));
}
*return_sensitivity = !nautilus_trash_monitor_is_empty ();
} else if (strcmp (path, NAUTILUS_MENU_PATH_SELECT_ALL_ITEM) == 0) {
name = g_strdup (_("_Select All Files"));
*return_sensitivity = !fm_directory_view_is_empty (directory_view);
} else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_REMOVE_CUSTOM_ICONS) == 0) {
if (nautilus_g_list_more_than_one_item (selection)) {
name = g_strdup (_("R_emove Custom Images"));
} else {
name = g_strdup (_("R_emove Custom Image"));
}
*return_sensitivity = files_have_any_custom_images (selection);
} else if (strcmp (path, FM_DIRECTORY_VIEW_MENU_PATH_RESET_BACKGROUND) == 0) {
name = g_strdup (_("Reset _Background"));
*return_sensitivity = nautilus_directory_background_is_set
(fm_directory_view_get_background (directory_view));
} else {
name = "";
g_assert_not_reached ();
}
if (!include_accelerator_underbars) {
stripped = nautilus_str_strip_chr (name, '_');
g_free (name);
name = stripped;
}
*return_name = name;
}
static void
set_menu_item_path (GtkMenuItem *item, const char *path)
{
/* set_data_full is unhappy if you give it a destroy_func
* and a NULL, even though it would work fine in this case.
*/
if (path == NULL) {
return;
}
gtk_object_set_data_full (GTK_OBJECT (item),
"path",
g_strdup (path),
g_free);
}
/* Append a new menu item to a GtkMenu, with the FMDirectoryView *
* being the callback data.
*/
static void
append_gtk_menu_item (FMDirectoryView *view,
GtkMenu *menu,
GList *files,
const char *menu_path,
const char *verb_path,
GtkSignalFunc callback)
{
GtkWidget *menu_item;
char *label_string;
gboolean sensitive;
compute_menu_item_info (view, menu_path, files, FALSE, &label_string, &sensitive);
menu_item = gtk_menu_item_new_with_label (label_string);
g_free (label_string);
set_menu_item_path (GTK_MENU_ITEM (menu_item), verb_path);
gtk_signal_connect (GTK_OBJECT (menu_item),
"activate",
callback,
view);
finish_appending_menu_item (menu, menu_item, sensitive);
}
static void
append_selection_menu_subtree (FMDirectoryView *view,
GtkMenu *parent_menu,
GtkMenu *child_menu,
GList *files,
const char *path)
{
GtkWidget *menu_item;
char *label_string;
gboolean sensitive;
compute_menu_item_info (view, path, files, FALSE, &label_string, &sensitive);
menu_item = gtk_menu_item_new_with_label (label_string);
g_free (label_string);
finish_appending_menu_item (parent_menu, menu_item, sensitive);
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu_item),
GTK_WIDGET (child_menu));
}
/* fm_directory_view_insert_context_menu_item:
*
* Insert a menu item into a context menu for a directory view.
*
* @view: The FMDirectoryView in question.
* @menu: The context menu in which to insert the new item.
* @label: The user-visible text to appear in the menu item.
* @identifier: A string that uniquely distinguishes this item from other
* items in this menu. These can be published so that subclasses
* can locate specific menu items for modification, positioning,
* or removing. Pass NULL if you don't want subclasses to be able
* to discover this item.
* @position: The index at which to insert the new item.
* @callback: The function that's called when this item is selected. Note that
* the second parameter (the "callback data") is always @view.
* @sensitive: Whether or not this item should be sensitive.
*/
GtkMenuItem *
fm_directory_view_insert_context_menu_item (FMDirectoryView *view,
GtkMenu *menu,
const char *label,
const char *identifier,
int position,
void (* callback) (GtkMenuItem *, FMDirectoryView *),
gboolean sensitive)
{
GtkWidget *menu_item;
guint accel_key;
menu_item = gtk_menu_item_new_with_label (label);
/* Add accelerator */
accel_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (menu_item)->child), label);
if (accel_key != GDK_VoidSymbol)
{
gtk_widget_add_accelerator (menu_item, "activate", gtk_accel_group_get_default (),
accel_key, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE);
}
/* Store command path in item, so we can find this item by command path later */
set_menu_item_path (GTK_MENU_ITEM (menu_item), identifier);
gtk_signal_connect (GTK_OBJECT (menu_item), "activate",
GTK_SIGNAL_FUNC (callback), view);
finish_inserting_menu_item (menu, menu_item, position, sensitive);
return GTK_MENU_ITEM (menu_item);
}
static void
fm_directory_view_append_context_menu_item (FMDirectoryView *view,
GtkMenu *menu,
const char *label,
const char *path,
void (* activate_handler) (GtkMenuItem *, FMDirectoryView *),
gboolean sensitive)
{
fm_directory_view_insert_context_menu_item
(view,
menu,
label,
path,
-1,
activate_handler,
sensitive);
}
static void
create_background_context_menu_zoom_items (FMDirectoryView *view,
GtkMenu *menu)
{
nautilus_gtk_menu_append_separator (menu);
fm_directory_view_append_context_menu_item (view, menu, _("Zoom In"), NULL, zoom_in_callback,
fm_directory_view_can_zoom_in (view));
fm_directory_view_append_context_menu_item (view, menu, _("Zoom Out"), NULL, zoom_out_callback,
fm_directory_view_can_zoom_out (view));
fm_directory_view_append_context_menu_item (view, menu, _("Normal Size"), NULL, zoom_default_callback, TRUE);
}
static void
fm_directory_view_real_create_background_context_menu_items (FMDirectoryView *view,
GtkMenu *menu)
{
/* FIXME: This should share code by using compute_menu_item_info,
* but can't because of the "use underline for control key shortcut"
* hack here.
*/
fm_directory_view_append_context_menu_item
(view, menu,
_("_New Folder"),
FM_DIRECTORY_VIEW_COMMAND_NEW_FOLDER,
GTK_SIGNAL_FUNC (new_folder_callback),
fm_directory_view_supports_creating_files (view));
if (fm_directory_view_supports_zooming (view)) {
create_background_context_menu_zoom_items (view, menu);
}
nautilus_gtk_menu_append_separator (menu);
append_gtk_menu_item (view,
menu,
NULL,
FM_DIRECTORY_VIEW_MENU_PATH_RESET_BACKGROUND,
FM_DIRECTORY_VIEW_COMMAND_RESET_BACKGROUND,
reset_background_callback);
}
static void
launch_application_from_menu_item (GtkMenuItem *menu_item, gpointer callback_data)
{
ApplicationLaunchParameters *launch_parameters;
g_assert (GTK_IS_MENU_ITEM (menu_item));
g_assert (callback_data != NULL);
launch_parameters = (ApplicationLaunchParameters *)callback_data;
fm_directory_view_launch_application
(launch_parameters->application,
launch_parameters->uri,
launch_parameters->directory_view);
}
static void
view_uri_from_menu_item (GtkMenuItem *menu_item, gpointer callback_data)
{
ViewerLaunchParameters *launch_parameters;
g_assert (GTK_IS_MENU_ITEM (menu_item));
g_assert (callback_data != NULL);
launch_parameters = (ViewerLaunchParameters *)callback_data;
switch_location_and_view (launch_parameters->identifier,
launch_parameters->uri,
launch_parameters->directory_view);
}
static void
add_application_to_gtk_menu (FMDirectoryView *directory_view,
GtkMenu *menu,
GnomeVFSMimeApplication *application,
const char *uri)
{
GtkWidget *menu_item;
ApplicationLaunchParameters *launch_parameters;
char *label_string;
g_assert (GTK_IS_MENU (menu));
label_string = g_strdup (application->name);
menu_item = gtk_menu_item_new_with_label (label_string);
g_free (label_string);
launch_parameters = application_launch_parameters_new
(application, uri, directory_view);
nautilus_gtk_signal_connect_free_data_custom
(GTK_OBJECT (menu_item),
"activate",
launch_application_from_menu_item,
launch_parameters,
(GtkDestroyNotify) application_launch_parameters_free);
finish_appending_menu_item (menu, menu_item, TRUE);
}
static void
add_component_to_gtk_menu (FMDirectoryView *directory_view,
GtkMenu *menu,
OAF_ServerInfo *component,
const char *uri)
{
GtkWidget *menu_item;
NautilusViewIdentifier *identifier;
ViewerLaunchParameters *launch_parameters;
char *label;
g_assert (GTK_IS_MENU (menu));
identifier = nautilus_view_identifier_new_from_content_view (component);
label = g_strdup_printf (_("%s Viewer"), identifier->name);
menu_item = gtk_menu_item_new_with_label (label);
g_free (label);
launch_parameters = viewer_launch_parameters_new
(identifier, uri, directory_view);
nautilus_view_identifier_free (identifier);
nautilus_gtk_signal_connect_free_data_custom
(GTK_OBJECT (menu_item),
"activate",
view_uri_from_menu_item,
launch_parameters,
(GtkDestroyNotify) viewer_launch_parameters_free);
finish_appending_menu_item (menu, menu_item, TRUE);
}
static GtkMenu *
create_open_with_gtk_menu (FMDirectoryView *view, GList *files)
{
GtkMenu *open_with_menu;
GList *applications, *components;
GList *node;
char *uri;
NautilusDirectory *directory;
open_with_menu = GTK_MENU (gtk_menu_new ());
gtk_widget_show (GTK_WIDGET (open_with_menu));
/* This menu is only displayed when there's one selected item. */
if (nautilus_g_list_exactly_one_item (files)) {
uri = nautilus_file_get_uri (NAUTILUS_FILE (files->data));
directory = nautilus_directory_get (uri);
applications = nautilus_mime_get_short_list_applications_for_uri (directory, NAUTILUS_FILE (files->data));
for (node = applications; node != NULL; node = node->next) {
add_application_to_gtk_menu (view, open_with_menu, node->data, uri);
}
gnome_vfs_mime_application_list_free (applications);
append_gtk_menu_item (view,
open_with_menu,
files,
FM_DIRECTORY_VIEW_MENU_PATH_OTHER_APPLICATION,
FM_DIRECTORY_VIEW_COMMAND_OTHER_APPLICATION,
other_application_callback);
nautilus_gtk_menu_append_separator (open_with_menu);
components = nautilus_mime_get_short_list_components_for_uri (directory, NAUTILUS_FILE (files->data));
for (node = components; node != NULL; node = node->next) {
add_component_to_gtk_menu (view, open_with_menu, node->data, uri);
}
gnome_vfs_mime_component_list_free (components);
nautilus_directory_unref (directory);
g_free (uri);
append_gtk_menu_item (view,
open_with_menu,
files,
FM_DIRECTORY_VIEW_MENU_PATH_OTHER_VIEWER,
FM_DIRECTORY_VIEW_COMMAND_OTHER_VIEWER,
other_viewer_callback);
}
return open_with_menu;
}
static void
fm_directory_view_real_create_selection_context_menu_items (FMDirectoryView *view,
GtkMenu *menu,
GList *files)
{
gboolean link_in_selection;
/* Check for special links */
link_in_selection = special_link_in_selection (view);
append_gtk_menu_item (view, menu, files,
FM_DIRECTORY_VIEW_MENU_PATH_OPEN,
FM_DIRECTORY_VIEW_COMMAND_OPEN,
open_callback);
append_gtk_menu_item (view, menu, files,
FM_DIRECTORY_VIEW_MENU_PATH_OPEN_IN_NEW_WINDOW,
FM_DIRECTORY_VIEW_COMMAND_OPEN_IN_NEW_WINDOW,
open_in_new_window_callback);
append_selection_menu_subtree (view, menu,
create_open_with_gtk_menu (view, files), files,
FM_DIRECTORY_VIEW_MENU_PATH_OPEN_WITH);
nautilus_gtk_menu_append_separator (menu);
/* Don't add item if Trash link is in selection */
if (!link_in_selection) {
append_gtk_menu_item (view, menu, files,
FM_DIRECTORY_VIEW_MENU_PATH_TRASH,
FM_DIRECTORY_VIEW_COMMAND_TRASH,
trash_callback);
}
if (!link_in_selection) {
append_gtk_menu_item (view, menu, files,
FM_DIRECTORY_VIEW_MENU_PATH_DUPLICATE,
FM_DIRECTORY_VIEW_COMMAND_DUPLICATE,
duplicate_callback);
append_gtk_menu_item (view, menu, files,
FM_DIRECTORY_VIEW_MENU_PATH_CREATE_LINK,
FM_DIRECTORY_VIEW_COMMAND_CREATE_LINK,
create_link_callback);
}
append_gtk_menu_item (view, menu, files,
FM_DIRECTORY_VIEW_MENU_PATH_SHOW_PROPERTIES,
FM_DIRECTORY_VIEW_COMMAND_SHOW_PROPERTIES,
open_properties_window_callback);
append_gtk_menu_item (view, menu, files,
FM_DIRECTORY_VIEW_MENU_PATH_REMOVE_CUSTOM_ICONS,
FM_DIRECTORY_VIEW_COMMAND_REMOVE_CUSTOM_ICONS,
remove_custom_icons_callback);
}
static void
bonobo_launch_application_callback (BonoboUIComponent *component, gpointer callback_data, const char *path)
{
ApplicationLaunchParameters *launch_parameters;
launch_parameters = (ApplicationLaunchParameters *) callback_data;
fm_directory_view_launch_application
(launch_parameters->application,
launch_parameters->uri,
launch_parameters->directory_view);
}
static void
bonobo_open_location_with_viewer_callback (BonoboUIComponent *component, gpointer callback_data, const char *path)
{
ViewerLaunchParameters *launch_parameters;
launch_parameters = (ViewerLaunchParameters *)callback_data;
switch_location_and_view (launch_parameters->identifier,
launch_parameters->uri,
launch_parameters->directory_view);
}
static void
add_open_with_app_bonobo_menu_item (BonoboUIComponent *ui,
const char *label,
gpointer callback,
gpointer callback_data,
GDestroyNotify destroy_notify)
{
char *escaped_label, *verb_name;
escaped_label = nautilus_str_double_underscores (label);
nautilus_bonobo_add_menu_item (ui, FM_DIRECTORY_VIEW_MENU_PATH_APPLICATIONS_PLACEHOLDER,
escaped_label);
verb_name = nautilus_bonobo_get_menu_item_verb_name (label);
bonobo_ui_component_add_verb_full (ui, verb_name, callback, callback_data, destroy_notify);
g_free (escaped_label);
g_free (verb_name);
}
static void
add_open_with_viewer_bonobo_menu_item (BonoboUIComponent *ui,
const char *label,
gpointer callback,
gpointer callback_data,
GDestroyNotify destroy_notify)
{
char *escaped_label, *verb_name;
escaped_label = nautilus_str_double_underscores (label);
nautilus_bonobo_add_menu_item (ui, FM_DIRECTORY_VIEW_MENU_PATH_VIEWERS_PLACEHOLDER,
escaped_label);
verb_name = g_strdup_printf ("verb:%s", label);
bonobo_ui_component_add_verb_full (ui, verb_name, callback, callback_data, destroy_notify);
g_free (escaped_label);
}
static void
add_application_to_bonobo_menu (FMDirectoryView *directory_view,
GnomeVFSMimeApplication *application,
const char *uri)
{
ApplicationLaunchParameters *launch_parameters;
launch_parameters = application_launch_parameters_new
(application, uri, directory_view);
add_open_with_app_bonobo_menu_item (directory_view->details->ui,
application->name,
bonobo_launch_application_callback,
launch_parameters,
(GDestroyNotify) application_launch_parameters_free);
}
static void
add_component_to_bonobo_menu (FMDirectoryView *directory_view,
OAF_ServerInfo *content_view,
const char *uri)
{
NautilusViewIdentifier *identifier;
ViewerLaunchParameters *launch_parameters;
char *label;
identifier = nautilus_view_identifier_new_from_content_view (content_view);
launch_parameters = viewer_launch_parameters_new (identifier, uri, directory_view);
nautilus_view_identifier_free (identifier);
label = g_strdup_printf (_("%s Viewer"),
launch_parameters->identifier->name);
add_open_with_viewer_bonobo_menu_item (directory_view->details->ui,
label,
bonobo_open_location_with_viewer_callback,
launch_parameters,
(GDestroyNotify) viewer_launch_parameters_free);
g_free (label);
}
static void
update_one_menu_item (FMDirectoryView *view,
GList *selection,
const char *menu_path,
const char *verb_path)
{
char *label_string;
gboolean sensitive;
compute_menu_item_info (view, menu_path, selection, TRUE, &label_string, &sensitive);
nautilus_bonobo_set_sensitive (view->details->ui, verb_path, sensitive);
nautilus_bonobo_set_label (view->details->ui, menu_path, label_string);
g_free (label_string);
}
static void
reset_bonobo_trash_delete_menu (FMDirectoryView *view, GList *selection)
{
if (fm_directory_all_selected_items_in_trash (view)) {
nautilus_bonobo_set_description (view->details->ui,
FM_DIRECTORY_VIEW_MENU_PATH_TRASH,
_("Delete all selected items permanently"));
nautilus_bonobo_set_accelerator (view->details->ui,
FM_DIRECTORY_VIEW_MENU_PATH_TRASH,
"");
} else {
nautilus_bonobo_set_description (view->details->ui,
FM_DIRECTORY_VIEW_MENU_PATH_TRASH,
_("Move all selected items to the Trash"));
nautilus_bonobo_set_accelerator (view->details->ui,
FM_DIRECTORY_VIEW_MENU_PATH_TRASH,
"*Control*t");
}
update_one_menu_item (view, selection,
FM_DIRECTORY_VIEW_MENU_PATH_TRASH,
FM_DIRECTORY_VIEW_COMMAND_TRASH);
}
static void
reset_bonobo_open_with_menu (FMDirectoryView *view, GList *selection)
{
GList *applications, *components;
GList *node;
char *uri;
NautilusDirectory *directory;
/* Clear any previous inserted items in the applications and viewers placeholders */
/* FIXME bugzilla.eazel.com 3568: We are leaking here. We need to remove the verbs also */
nautilus_bonobo_remove_menu_items (view->details->ui, FM_DIRECTORY_VIEW_MENU_PATH_APPLICATIONS_PLACEHOLDER);
nautilus_bonobo_remove_menu_items (view->details->ui, FM_DIRECTORY_VIEW_MENU_PATH_VIEWERS_PLACEHOLDER);
/* This menu is only displayed when there's one selected item. */
if (nautilus_g_list_exactly_one_item (selection)) {
uri = nautilus_file_get_uri (NAUTILUS_FILE (selection->data));
directory = nautilus_directory_get (uri);
applications = nautilus_mime_get_short_list_applications_for_uri (directory, NAUTILUS_FILE (selection->data));
for (node = applications; node != NULL; node = node->next) {
add_application_to_bonobo_menu (view, node->data, uri);
}
gnome_vfs_mime_application_list_free (applications);
components = nautilus_mime_get_short_list_components_for_uri (directory, NAUTILUS_FILE (selection->data));
for (node = components; node != NULL; node = node->next) {
add_component_to_bonobo_menu (view, node->data, uri);
}
gnome_vfs_mime_component_list_free (components);
nautilus_directory_unref (directory);
g_free (uri);
}
}
static void
fm_directory_view_real_merge_menus (FMDirectoryView *view)
{
BonoboUIVerb verbs [] = {
BONOBO_UI_VERB ("New Folder", (BonoboUIVerbFn)new_folder_callback),
BONOBO_UI_VERB ("Open", (BonoboUIVerbFn)open_callback),
BONOBO_UI_VERB ("OpenNew", (BonoboUIVerbFn)open_in_new_window_callback),
BONOBO_UI_VERB ("OtherApplication", (BonoboUIVerbFn)other_application_callback),
BONOBO_UI_VERB ("OtherViewer", (BonoboUIVerbFn)other_viewer_callback),
BONOBO_UI_VERB ("Show Properties", (BonoboUIVerbFn)open_properties_window_callback),
BONOBO_UI_VERB ("Trash", (BonoboUIVerbFn)trash_callback),
BONOBO_UI_VERB ("Duplicate", (BonoboUIVerbFn)duplicate_callback),
BONOBO_UI_VERB ("Create Link", (BonoboUIVerbFn)create_link_callback),
BONOBO_UI_VERB ("Empty Trash", bonobo_menu_empty_trash_callback),
BONOBO_UI_VERB ("Select All", bonobo_menu_select_all_callback),
BONOBO_UI_VERB ("Remove Custom Icons", (BonoboUIVerbFn)remove_custom_icons_callback),
BONOBO_UI_VERB_END
};
/* This BonoboUIComponent is made automatically, and its lifetime is
* controlled automatically. We don't need to explicitly ref or unref it.
*/
view->details->ui = nautilus_view_set_up_ui (view->details->nautilus_view,
DATADIR,
"nautilus-directory-view-ui.xml",
"nautilus");
bonobo_ui_component_add_verb_list_with_data (view->details->ui, verbs, view);
gtk_signal_connect_object (GTK_OBJECT (fm_directory_view_get_background (view)),
"settings_changed",
schedule_update_menus,
GTK_OBJECT (view));
}
static void
fm_directory_view_real_update_menus (FMDirectoryView *view)
{
GList *selection;
selection = fm_directory_view_get_selection (view);
update_one_menu_item (view, selection,
FM_DIRECTORY_VIEW_MENU_PATH_NEW_FOLDER,
FM_DIRECTORY_VIEW_COMMAND_NEW_FOLDER);
update_one_menu_item (view, selection,
FM_DIRECTORY_VIEW_MENU_PATH_OPEN,
FM_DIRECTORY_VIEW_COMMAND_OPEN);
update_one_menu_item (view, selection,
FM_DIRECTORY_VIEW_MENU_PATH_OPEN_IN_NEW_WINDOW,
FM_DIRECTORY_VIEW_COMMAND_OPEN_IN_NEW_WINDOW);
reset_bonobo_open_with_menu (view, selection);
reset_bonobo_trash_delete_menu (view, selection);
update_one_menu_item (view, selection,
FM_DIRECTORY_VIEW_MENU_PATH_DUPLICATE,
FM_DIRECTORY_VIEW_COMMAND_DUPLICATE);
update_one_menu_item (view, selection,
FM_DIRECTORY_VIEW_MENU_PATH_CREATE_LINK,
FM_DIRECTORY_VIEW_COMMAND_CREATE_LINK);
update_one_menu_item (view, selection,
FM_DIRECTORY_VIEW_MENU_PATH_SHOW_PROPERTIES,
FM_DIRECTORY_VIEW_COMMAND_SHOW_PROPERTIES);
update_one_menu_item (view, selection,
FM_DIRECTORY_VIEW_MENU_PATH_EMPTY_TRASH,
FM_DIRECTORY_VIEW_COMMAND_EMPTY_TRASH);
update_one_menu_item (view, selection,
FM_DIRECTORY_VIEW_MENU_PATH_REMOVE_CUSTOM_ICONS,
FM_DIRECTORY_VIEW_COMMAND_REMOVE_CUSTOM_ICONS);
update_one_menu_item (view, selection,
NAUTILUS_MENU_PATH_SELECT_ALL_ITEM,
NAUTILUS_COMMAND_SELECT_ALL);
nautilus_file_list_free (selection);
}
static GtkMenu *
create_selection_context_menu (FMDirectoryView *view)
{
GtkMenu *menu;
GList *selected_files;
g_assert (FM_IS_DIRECTORY_VIEW (view));
selected_files = fm_directory_view_get_selection (view);
/* We've seen this happen in at least bugzilla.eazel.com 3322 */
g_return_val_if_fail (selected_files != NULL, NULL);
menu = GTK_MENU (gtk_menu_new ());
/* Attach selection to menu, and free it when menu is freed.
* This lets menu item callbacks hold onto the files parameter.
*/
gtk_object_set_data_full (GTK_OBJECT (menu),
"selected_items",
selected_files,
(GtkDestroyNotify) nautilus_file_list_free);
gtk_signal_emit (GTK_OBJECT (view),
signals[CREATE_SELECTION_CONTEXT_MENU_ITEMS],
menu, selected_files);
return menu;
}
/**
* fm_directory_view_create_background_context_menu_items:
*
* Add background menu items (i.e., those not dependent on a particular file)
* to a context menu.
* @view: An FMDirectoryView.
* @menu: The menu being constructed. Could be a background menu or an item-specific
* menu, because the background items are present in both.
*
**/
static void
fm_directory_view_create_background_context_menu_items (FMDirectoryView *view,
GtkMenu *menu)
{
gtk_signal_emit (GTK_OBJECT (view),
signals[CREATE_BACKGROUND_CONTEXT_MENU_ITEMS],
menu);
}
static GtkMenu *
create_background_context_menu (FMDirectoryView *view)
{
GtkMenu *menu;
menu = GTK_MENU (gtk_menu_new ());
fm_directory_view_create_background_context_menu_items (view, menu);
return menu;
}
/**
* fm_directory_view_pop_up_selection_context_menu
*
* Pop up a context menu appropriate to the selected items at the last right click location.
* @view: FMDirectoryView of interest.
* @file: The model object for which a menu should be popped up.
*
* Return value: NautilusDirectory for this view.
*
**/
void
fm_directory_view_pop_up_selection_context_menu (FMDirectoryView *view)
{
GtkMenu *menu;
g_assert (FM_IS_DIRECTORY_VIEW (view));
menu = create_selection_context_menu (view);
if (menu != NULL) {
nautilus_pop_up_context_menu (menu,
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT,
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT,
0);
}
}
/**
* fm_directory_view_pop_up_background_context_menu
*
* Pop up a context menu appropriate to the view globally at the last right click location.
* @view: FMDirectoryView of interest.
*
* Return value: NautilusDirectory for this view.
*
**/
void
fm_directory_view_pop_up_background_context_menu (FMDirectoryView *view)
{
g_assert (FM_IS_DIRECTORY_VIEW (view));
nautilus_pop_up_context_menu (create_background_context_menu (view),
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT,
NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT,
0);
}
static void
schedule_update_menus (FMDirectoryView *view)
{
g_assert (FM_IS_DIRECTORY_VIEW (view));
view->details->menu_states_untrustworthy = TRUE;
if (view->details->menus_merged
&& view->details->update_menus_idle_id == 0) {
view->details->update_menus_idle_id
= gtk_idle_add (update_menus_idle_callback, view);
}
}
/**
* fm_directory_view_notify_selection_changed:
*
* Notify this view that the selection has changed. This is normally
* called only by subclasses.
* @view: FMDirectoryView whose selection has changed.
*
**/
void
fm_directory_view_notify_selection_changed (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
/* Schedule a display of the new selection. */
if (view->details->display_selection_idle_id == 0)
view->details->display_selection_idle_id
= gtk_idle_add (display_selection_info_idle_callback,
view);
if (view->details->batching_selection_level != 0) {
view->details->selection_changed_while_batched = TRUE;
} else {
/* Here is the work we do only when we're not
* batching selection changes. In other words, it's the slower
* stuff that we don't want to slow down selection techniques
* such as rubberband-selecting in icon view.
*/
/* Schedule an update of menu item states to match selection */
schedule_update_menus (view);
}
}
static gboolean
file_is_launchable (NautilusFile *file)
{
return !nautilus_file_is_directory (file)
&& nautilus_file_can_get_permissions (file)
&& nautilus_file_can_execute (file);
}
static void
report_broken_symbolic_link (FMDirectoryView *view, NautilusFile *file)
{
char *target_path;
char *prompt;
GnomeDialog *dialog;
GList file_as_list;
g_assert (nautilus_file_is_broken_symbolic_link (file));
target_path = nautilus_file_get_symbolic_link_target_path (file);
if (target_path == NULL) {
prompt = g_strdup_printf (_("This link can't be used, because it has no target. "
"Do you want to put this link in the trash?"));
} else {
prompt = g_strdup_printf (_("This link can't be used, because its target \"%s\" doesn't exist. "
"Do you want to put this link in the trash?"),
target_path);
}
dialog = nautilus_yes_no_dialog (prompt,
_("Broken Link"),
_("Throw Away"),
GNOME_STOCK_BUTTON_CANCEL,
get_containing_window (view));
gnome_dialog_set_default (dialog, GNOME_CANCEL);
/* Make this modal to avoid problems with reffing the view & file
* to keep them around in case the view changes, which would then
* cause the old view not to be destroyed, which would cause its
* merged Bonobo items not to be un-merged. Maybe we need to unmerge
* explicitly when disconnecting views instead of relying on the
* unmerge in Destroy. But since BonoboUIHandler is probably going
* to change wildly, I don't want to mess with this now.
*/
if (gnome_dialog_run (dialog) == GNOME_OK) {
file_as_list.data = file;
file_as_list.next = NULL;
file_as_list.prev = NULL;
fm_directory_view_trash_or_delete_files (view, &file_as_list);
}
g_free (target_path);
g_free (prompt);
}
typedef struct {
FMDirectoryView *view;
NautilusFile *file;
gboolean use_new_window;
} ActivateParameters;
static void
activate_callback (NautilusFile *file, gpointer callback_data)
{
ActivateParameters *parameters;
FMDirectoryView *view;
char *uri, *command, *executable_path;
GnomeVFSMimeActionType action_type;
GnomeVFSMimeApplication *application;
gboolean performed_special_handling;
NautilusDirectory *directory;
parameters = callback_data;
view = FM_DIRECTORY_VIEW (parameters->view);
uri = nautilus_file_get_activation_uri (file);
performed_special_handling = FALSE;
/* Note that we check for FILE_TYPE_SYMBOLIC_LINK only here,
* not specifically for broken-ness, because the file type
* will be the target's file type in the non-broken case.
*/
if (nautilus_file_is_broken_symbolic_link (file)) {
report_broken_symbolic_link (view, file);
performed_special_handling = TRUE;
} else if (nautilus_istr_has_prefix (uri, "command:")) {
/* don't allow command execution from remote uris to partially mitigate
* the security risk of executing arbitrary commands. We want to
* further constrain this before 1.0, as expressed bug 2390 */
if (!nautilus_file_is_local (file)) {
nautilus_error_dialog (_("Sorry, but you can't execute commands from a remote site due to security considerations."),
_("Can't execute remote links"), NULL);
performed_special_handling = TRUE;
} else {
/* FIXME bugzilla.eazel.com 2390: Quite a security hole here. */
command = g_strconcat (uri + 8, " &", NULL);
system (command);
g_free (command);
performed_special_handling = TRUE;
}
} else if (file_is_launchable (file)) {
/* FIXME bugzilla.eazel.com 2391: This should check if
* the activation URI points to something launchable,
* not the original file. Also, for symbolic links we
* need to check the X bit on the target file, not on
* the original.
*/
/* Launch executables to activate them. */
/* FIXME bugzilla.eazel.com 1773: This is a lame way
* to run command-line tools, since there's no
* terminal for the output.
*/
executable_path = gnome_vfs_get_local_path_from_uri (uri);
/* Non-local executables don't get launched. They fall through
* and act like non-executables.
*/
if (executable_path != NULL) {
nautilus_launch_application_from_command (executable_path, NULL);
g_free (executable_path);
performed_special_handling = TRUE;
}
}
if (!performed_special_handling) {
directory = nautilus_directory_get (uri);
action_type = nautilus_mime_get_default_action_type_for_uri (directory, file);
application = nautilus_mime_get_default_application_for_uri (directory, file);
/* We need to check for the case of having
* GNOME_VFS_MIME_ACTION_TYPE_APPLICATION as the
* action but having a NULL application returned.
*/
if (action_type == GNOME_VFS_MIME_ACTION_TYPE_APPLICATION && application == NULL) {
action_type = GNOME_VFS_MIME_ACTION_TYPE_COMPONENT;
}
if (action_type == GNOME_VFS_MIME_ACTION_TYPE_APPLICATION) {
fm_directory_view_launch_application (application, uri, view);
} else {
/* If the action type is unspecified, treat it like
* the component case. This is most likely to happen
* (only happens?) when there are no registered
* viewers or apps, or there are errors in the
* mime.keys files.
*/
g_assert (action_type == GNOME_VFS_MIME_ACTION_TYPE_NONE
|| action_type == GNOME_VFS_MIME_ACTION_TYPE_COMPONENT);
fm_directory_view_switch_location
(view, uri, parameters->use_new_window);
}
if (application != NULL) {
gnome_vfs_mime_application_free (application);
}
nautilus_directory_unref (directory);
}
g_free (uri);
}
/**
* fm_directory_view_activate_file:
*
* Activate a file in this view. This might involve switching the displayed
* location for the current window, or launching an application.
* @view: FMDirectoryView in question.
* @file: A NautilusFile representing the file in this view to activate.
* @use_new_window: Should this item be opened in a new window?
*
**/
static void
fm_directory_view_activate_file (FMDirectoryView *view,
NautilusFile *file,
gboolean use_new_window)
{
ActivateParameters *parameters;
GList *attributes;
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
g_return_if_fail (NAUTILUS_IS_FILE (file));
/* Might have to read some of the file to activate it. */
attributes = g_list_prepend (NULL, NAUTILUS_FILE_ATTRIBUTE_ACTIVATION_URI);
attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_FILE_TYPE);
parameters = g_new (ActivateParameters, 1);
parameters->view = view;
parameters->file = file;
parameters->use_new_window = use_new_window;
nautilus_file_call_when_ready
(file, attributes, activate_callback, parameters);
/* FIXME bugzilla.eazel.com 2392: Need a timed wait here too. */
g_list_free (attributes);
}
/**
* fm_directory_view_activate_files:
*
* Activate a list of files. Each one might launch with an application or
* with a component. This is normally called only by subclasses.
* @view: FMDirectoryView in question.
* @files: A GList of NautilusFiles to activate.
*
**/
void
fm_directory_view_activate_files (FMDirectoryView *view,
GList *files)
{
GList *node;
int file_count;
gboolean use_new_window;
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
/* If there's a single file to activate, check user's preference whether
* to open it in this window or a new window. If there is more than one
* file to activate, open each one in a new window. Don't try to choose
* one special one to replace the current window's contents; we tried this
* but it proved mysterious in practice.
*/
file_count = g_list_length (files);
use_new_window = file_count > 1
|| nautilus_preferences_get_boolean
(NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW, FALSE);
if (!use_new_window || fm_directory_view_confirm_multiple_windows (view, file_count)) {
for (node = files; node != NULL; node = node->next) {
fm_directory_view_activate_file
(view, node->data, use_new_window);
}
}
}
/**
* fm_directory_view_load_uri:
*
* Switch the displayed location to a new uri. If the uri is not valid,
* the location will not be switched; user feedback will be provided instead.
* @view: FMDirectoryView whose location will be changed.
* @uri: A string representing the uri to switch to.
*
**/
static void
fm_directory_view_load_uri (FMDirectoryView *view,
const char *uri)
{
NautilusDirectory *old_model;
GList *attributes;
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
g_return_if_fail (uri != NULL);
fm_directory_view_stop (view);
fm_directory_view_clear (view);
/* Update menus when directory is empty, before going to new
* location, so they won't have any false lingering knowledge
* of old selection.
*/
schedule_update_menus (view);
disconnect_model_handlers (view);
old_model = view->details->model;
view->details->model = nautilus_directory_get (uri);
nautilus_directory_unref (old_model);
attributes = g_list_append (NULL, NAUTILUS_FILE_ATTRIBUTE_METADATA);
nautilus_directory_call_when_ready
(view->details->model,
attributes,
metadata_ready_callback, view);
g_list_free (attributes);
}
static void
finish_loading_uri (FMDirectoryView *view)
{
GList *attributes;
nautilus_view_report_load_underway (view->details->nautilus_view);
/* Tell interested parties that we've begun loading this directory now.
* Subclasses use this to know that the new metadata is now available.
*/
fm_directory_view_begin_loading (view);
schedule_timeout_display_of_pending_files (view);
view->details->loading = TRUE;
/* Start loading. */
attributes = g_list_prepend (NULL,
NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_COUNT);
attributes = g_list_prepend (attributes,
NAUTILUS_FILE_ATTRIBUTE_TOP_LEFT_TEXT);
nautilus_directory_file_monitor_add (view->details->model, view,
attributes, TRUE);
g_list_free (attributes);
/* Attach a handler to get any further files that show up as we
* load and sychronize. We won't miss any files because this
* signal is emitted from an idle routine and so we will be
* connected before the next time it is emitted.
*/
view->details->files_added_handler_id = gtk_signal_connect
(GTK_OBJECT (view->details->model),
"files_added",
files_added_callback,
view);
view->details->files_changed_handler_id = gtk_signal_connect
(GTK_OBJECT (view->details->model),
"files_changed",
files_changed_callback,
view);
}
static void
metadata_ready_callback (NautilusDirectory *directory,
GList *files,
gpointer callback_data)
{
FMDirectoryView *view;
view = callback_data;
g_assert (FM_IS_DIRECTORY_VIEW (view));
g_assert (view->details->model == directory);
finish_loading_uri (view);
}
static void
get_required_metadata_keys (FMDirectoryView *view,
GList **directory_keys_result,
GList **file_keys_result)
{
GList *directory_keys;
g_assert (FM_IS_DIRECTORY_VIEW (view));
g_assert (directory_keys_result != NULL);
g_assert (file_keys_result != NULL);
directory_keys = NULL;
/* This needs to be a list of all the metadata needed.
* For now, it's kinda hard-coded. Later we might want
* to gather this info from various sources.
*/
directory_keys = g_list_prepend (directory_keys,
NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_COLOR);
directory_keys = g_list_prepend (directory_keys,
NAUTILUS_METADATA_KEY_DIRECTORY_BACKGROUND_IMAGE);
*directory_keys_result = directory_keys;
*file_keys_result = NULL;
}
NautilusStringList *
fm_directory_view_get_emblem_names_to_exclude (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), NULL);
return NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
get_emblem_names_to_exclude, (view));
}
static NautilusStringList *
real_get_emblem_names_to_exclude (FMDirectoryView *view)
{
g_assert (FM_IS_DIRECTORY_VIEW (view));
return nautilus_string_list_new_from_string (NAUTILUS_FILE_EMBLEM_NAME_TRASH, TRUE);
}
/**
* fm_directory_view_merge_menus:
*
* Add this view's menus to the window's menu bar.
* @view: FMDirectoryView in question.
*/
static void
fm_directory_view_merge_menus (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
/* Remember that the menus have been merged so that we
* won't try to update them before merging them.
*/
view->details->menus_merged = TRUE;
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
merge_menus, (view));
}
static void
disconnect_handler (FMDirectoryView *view, int *id)
{
if (*id != 0) {
gtk_signal_disconnect (GTK_OBJECT (view->details->model), *id);
*id = 0;
}
}
static void
disconnect_model_handlers (FMDirectoryView *view)
{
disconnect_handler (view, &view->details->files_added_handler_id);
disconnect_handler (view, &view->details->files_changed_handler_id);
if (view->details->model != NULL) {
nautilus_directory_file_monitor_remove (view->details->model, view);
nautilus_directory_cancel_callback (view->details->model,
metadata_ready_callback,
view);
}
}
/**
* fm_directory_view_select_all:
*
* select all the items in the view
*
**/
void
fm_directory_view_select_all (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
select_all, (view));
}
/**
* fm_directory_view_set_selection:
*
* set the selection to the items identified in @selection. @selection
* should be a list of NautilusFiles
*
**/
void
fm_directory_view_set_selection (FMDirectoryView *view, GList *selection)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
set_selection, (view, selection));
}
/**
* fm_directory_view_reveal_selection:
*
* Scroll as necessary to reveal the selected items.
**/
void
fm_directory_view_reveal_selection (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
reveal_selection, (view));
}
/**
* fm_directory_view_stop:
*
* Stop the current ongoing process, such as switching to a new uri.
* @view: FMDirectoryView in question.
*
**/
void
fm_directory_view_stop (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
unschedule_display_of_pending_files (view);
display_pending_files (view);
if (view->details->model != NULL) {
nautilus_directory_file_monitor_remove (view->details->model, view);
}
done_loading (view);
}
gboolean
fm_directory_view_is_read_only (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
return NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
is_read_only, (view));
}
gboolean
fm_directory_view_is_empty (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
return NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
is_empty, (view));
}
static gboolean
fm_directory_view_real_is_read_only (FMDirectoryView *view)
{
NautilusFile *directory_as_file;
gboolean result;
directory_as_file = get_directory_as_file (view);
result = !nautilus_file_can_write (directory_as_file);
nautilus_file_unref (directory_as_file);
return result;
}
gboolean
fm_directory_view_supports_creating_files (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
return NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
supports_creating_files, (view));
}
gboolean
fm_directory_view_accepts_dragged_files (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
return NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
accepts_dragged_files, (view));
}
static gboolean
showing_trash_directory (FMDirectoryView *view)
{
NautilusFile *directory_as_file;
gboolean result;
directory_as_file = get_directory_as_file (view);
result = nautilus_file_is_in_trash (directory_as_file);
nautilus_file_unref (directory_as_file);
return result;
}
static gboolean
fm_directory_view_real_supports_creating_files (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
return !fm_directory_view_is_read_only (view) && !showing_trash_directory (view);
}
static gboolean
fm_directory_view_real_accepts_dragged_files (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
return TRUE;
}
gboolean
fm_directory_view_supports_properties (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
return NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
supports_properties, (view));
}
static gboolean
fm_directory_view_real_supports_properties (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
return TRUE;
}
gboolean
fm_directory_view_supports_zooming (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
return NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
supports_zooming, (view));
}
static gboolean
fm_directory_view_real_supports_zooming (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
return TRUE;
}
/**
* fm_directory_view_update_menus:
*
* Update the sensitivity and wording of dynamic menu items.
* @view: FMDirectoryView in question.
*/
void
fm_directory_view_update_menus (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
NAUTILUS_CALL_VIRTUAL
(FM_DIRECTORY_VIEW_CLASS, view,
update_menus, (view));
view->details->menu_states_untrustworthy = FALSE;
}
static void
schedule_update_menus_callback (gpointer callback_data)
{
schedule_update_menus (FM_DIRECTORY_VIEW (callback_data));
}
static void
filtering_changed_callback (gpointer callback_data)
{
FMDirectoryView *directory_view;
char *same_uri;
directory_view = FM_DIRECTORY_VIEW (callback_data);
/* Hidden files are never shown on the desktop */
if (FM_IS_DESKTOP_ICON_VIEW (directory_view)) {
directory_view->details->show_hidden_files = FALSE;
directory_view->details->show_backup_files = FALSE;
return;
}
directory_view->details->show_hidden_files =
nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES, FALSE);
directory_view->details->show_backup_files =
nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES, FALSE);
/* Reload the current uri so that the filtering changes take place. */
if (directory_view->details->model != NULL) {
same_uri = nautilus_directory_get_uri (directory_view->details->model);
g_assert (same_uri != NULL);
fm_directory_view_load_uri (directory_view, same_uri);
g_free (same_uri);
}
}
char *
fm_directory_view_get_uri (FMDirectoryView *view)
{
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), NULL);
if (view->details->model == NULL) {
return NULL;
}
return nautilus_directory_get_uri (view->details->model);
}
void
fm_directory_view_move_copy_items (const GList *item_uris,
GdkPoint *relative_item_points,
const char *target_dir,
int copy_action,
int x,
int y,
FMDirectoryView *view)
{
int index, count;
if (relative_item_points) {
/* add the drop location to the icon offsets */
count = g_list_length ((GList *)item_uris);
for (index = 0; index < count; index++ ){
relative_item_points[index].x += x;
relative_item_points[index].y += y;
}
}
nautilus_file_operations_copy_move (item_uris, relative_item_points,
target_dir, copy_action, GTK_WIDGET (view));
}
gboolean
fm_directory_view_can_accept_item (NautilusFile *target_item,
const char *item_uri,
FMDirectoryView *view)
{
g_return_val_if_fail (NAUTILUS_IS_FILE (target_item), FALSE);
g_return_val_if_fail (item_uri != NULL, FALSE);
g_return_val_if_fail (FM_IS_DIRECTORY_VIEW (view), FALSE);
return nautilus_drag_can_accept_item (target_item, item_uri);
}
static gboolean
menu_item_matches_path (GtkMenuItem *item, const char *path)
{
return nautilus_strcmp ((const char *)gtk_object_get_data (GTK_OBJECT (item), "path"), path) == 0;
}
/**
* fm_directory_view_get_context_menu_index:
*
* Return index of specified menu item in the passed-in context menu.
* Return -1 if item is not found. This is intended for subclasses to
* use to properly position new items in the context menu.
*
* @menu: A GtkMenu, either the item-specific or background context menu
* as passed to _create_selection_context_menu_items or
* _create_background_context_menu_items.
* @verb_path: command name (e.g. "/commands/Open") whose index in @menu should be returned.
*/
int
fm_directory_view_get_context_menu_index (GtkMenu *menu, const char *verb_path)
{
GList *children, *node;
GtkMenuItem *menu_item;
int index;
int result;
g_return_val_if_fail (GTK_IS_MENU (menu), -1);
g_return_val_if_fail (verb_path != NULL, -1);
children = gtk_container_children (GTK_CONTAINER (menu));
result = -1;
for (node = children, index = 0; node != NULL; node = node->next, ++index) {
menu_item = GTK_MENU_ITEM (node->data);
if (menu_item_matches_path (menu_item, verb_path)) {
result = index;
break;
}
}
g_list_free (children);
return result;
}
static void
fm_directory_view_trash_state_changed_callback (NautilusTrashMonitor *trash_monitor,
gboolean state, gpointer callback_data)
{
FMDirectoryView *view;
view = (FMDirectoryView *)callback_data;
g_assert (FM_IS_DIRECTORY_VIEW (view));
schedule_update_menus (view);
}
void
fm_directory_view_start_batching_selection_changes (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
++view->details->batching_selection_level;
view->details->selection_changed_while_batched = FALSE;
}
void
fm_directory_view_stop_batching_selection_changes (FMDirectoryView *view)
{
g_return_if_fail (FM_IS_DIRECTORY_VIEW (view));
g_return_if_fail (view->details->batching_selection_level > 0);
if (--view->details->batching_selection_level == 0) {
if (view->details->selection_changed_while_batched) {
fm_directory_view_notify_selection_changed (view);
}
}
}
|