File: f.batch.cc

package info (click to toggle)
fotoxx 24.70-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 21,888 kB
  • sloc: cpp: 78,255; makefile: 116; xml: 52
file content (2420 lines) | stat: -rw-r--r-- 97,659 bytes parent folder | download
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
/********************************************************************************

   Fotocx - edit photos and manage collections

   Copyright 2007-2024 Michael Cornelison
   source code URL: https://kornelix.net
   contact: mkornelix@gmail.com

   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 3 of the License, or
   (at your option) any later version. See https://www.gnu.org/licenses

   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.

*********************************************************************************

   Fotocx image edit - Batch Menu functions

   m_batch_convert         batch rename, convert, rescale, move
   m_batch_copy_move       batch copy/move selected files to another folder
   m_batch_upright         find rotated files and upright them
   m_batch_deltrash        delete or trash selected files
   m_batch_RAW             convert RAW files to jpg/png/tif, 8/16 bits
   m_batch_overlay         add overlay image (caption ...) to selected files
   m_export_filelist       select files and generate a file list (text)
   m_export_files          select files and export to a folder

*********************************************************************************/

#define EX extern                                                                //  enable extern declarations
#include "fotocx.h"                                                              //  (variables in fotocx.h are refs)
#include <sys/wait.h>

using namespace zfuncs;

/********************************************************************************/


//  Batch file rename, convert, rescale, move

namespace batch_convert
{
   int      Fsametype, Fupsize, Fdownsize, maxww, maxhh;
   int      Fsamebpc, newbpc, jpeg_quality;
   int      Fdelete, Fcopymeta, Freplace;
   int      Fnewtext;
   int      Fplugdate, Fplugseq, Fplugname;
   ch       text1[100], text2[100];
   ch       newloc[500], newname[200], newext[8];
   int      baseseq, addseq;
   int      amount, thresh;
};


//  menu function

void m_batch_convert(GtkWidget *, ch *)
{
   using namespace batch_convert;

   int  batch_convert_dialog_event(zdialog *zd, ch *event);

   zdialog     *zd, *zdpop;
   int         zstat;
   ch          *infile, *outfile, tempfile[300];
   ch          *inloc, *inname, *inext;
   ch          *outloc, *outname, *outext;
   ch          *tempname, seqplug[8], seqnum[8];
   ch          plugyyyy[8], plugmm[4], plugdd[4];
   ch          **oldfiles, **newfiles;
   ch          *pp, *pp1, text[100];
   int         ii, jj, cc, err, Fjpeg;
   int         outww, outhh, outbpc, Fdelete2;
   int         Noldnew;
   float       scale, wscale, hscale;
   PXM         *pxmin, *pxmout;
   xxrec_t     *xxrec;

   F1_help_topic = "batch convert";

   Plog(1,"m_batch_convert \n");

   if (Findexvalid == 0) {
      zmessageACK(Mwin,"image index disabled");                                  //  no image index
      return;
   }
   
   if (Fblock("batch convert")) return;

/***
       ______________________________________________________________
      |                    Batch Convert                             |
      |                                                              |
      |  [Select Files]  N files selected                            |
      |                                                              |
      |  Replace Text  [__________________] --> [__________________] |           replace substring in file names
      |  New Name [________________________________________________] |           $yyyy $mm $dd $oldname $ss
      |  Sequence Numbers   base [_____]  adder [____]               |
      |  New Location [__________________________________] [browse]  |
      |                                                              |
      |  (o) tif  (o) png  (o) jpg [90] jpg quality  (o) no change   |
      |  Color Depth: (o) 8-bit  (o) 16-bit  (o) no change           |
      |  Max. Width [____]  Height [____]  [x] downsize  [x] upsize  |
      |  [x] Delete Originals  [x] Copy Metadata                     |
      |                                                              |
      |                                                [Proceed] [X] |
      |______________________________________________________________|

***/

   zd = zdialog_new("Batch Convert",Mwin,"Proceed"," X ",null);

   zdialog_add_widget(zd,"hbox","hbf","dialog",0,"space=5");
   zdialog_add_widget(zd,"button","files","hbf","Select Files","space=5");
   zdialog_add_widget(zd,"label","fcount","hbf","no files selected","space=10");

   zdialog_add_widget(zd,"hbox","hbrep","dialog");
   zdialog_add_widget(zd,"label","labrep1","hbrep","Replace Text","space=5");
   zdialog_add_widget(zd,"zentry","text1","hbrep",0,"expand");
   zdialog_add_widget(zd,"label","arrow","hbrep"," → ","space=5");
   zdialog_add_widget(zd,"zentry","text2","hbrep",0,"expand");
   zdialog_add_ttip(zd,"labrep1","replace substring within file name");

   zdialog_add_widget(zd,"hbox","hbname","dialog");
   zdialog_add_widget(zd,"label","labname","hbname","New Name","space=5");
   zdialog_add_widget(zd,"zentry","newname","hbname",0,"expand");
   zdialog_add_ttip(zd,"labname","plugins: (year month day old-name sequence) $yyyy  $mm  $dd  $oldname  $s");

   zdialog_add_widget(zd,"hbox","hbseq","dialog");
   zdialog_add_widget(zd,"label","labseq","hbseq","Sequence Numbers","space=5");
   zdialog_add_widget(zd,"label","space","hbseq",0,"space=8");
   zdialog_add_widget(zd,"label","labbase","hbseq","base","space=5");
   zdialog_add_widget(zd,"zspin","baseseq","hbseq","0|100000|1|0","size=5");
   zdialog_add_widget(zd,"label","space","hbseq","","space=3");
   zdialog_add_widget(zd,"label","labadder","hbseq","adder","space=5");
   zdialog_add_widget(zd,"zspin","addseq","hbseq","0|100|1|0","size=3");
   zdialog_add_widget(zd,"label","space","hbseq",0,"space=60");                  //  push back oversized entries

   zdialog_add_widget(zd,"hbox","hbloc","dialog");
   zdialog_add_widget(zd,"label","labloc","hbloc","New Location","space=5");
   zdialog_add_widget(zd,"zentry","newloc","hbloc",0,"expand");
   zdialog_add_widget(zd,"button","browse","hbloc","Browse","space=5");

   zdialog_add_widget(zd,"hbox","hbft","dialog");
   zdialog_add_widget(zd,"label","labtyp","hbft","New File Type","space=5");
   zdialog_add_widget(zd,"radio","tif","hbft","tif","space=4");
   zdialog_add_widget(zd,"radio","png","hbft","png","space=4");
   zdialog_add_widget(zd,"radio","jpg","hbft","jpg","space=2");
   zdialog_add_widget(zd,"zspin","jpgqual","hbft","10|100|1|90","size=3");
   zdialog_add_widget(zd,"label","labqual","hbft","jpg quality","space=6");
   zdialog_add_widget(zd,"radio","sametype","hbft","no change","space=6");

   zdialog_add_widget(zd,"hbox","hbcd","dialog");
   zdialog_add_widget(zd,"label","labcd","hbcd","Color Depth:","space=5");
   zdialog_add_widget(zd,"radio","8-bit","hbcd","8-bit","space=4");
   zdialog_add_widget(zd,"radio","16-bit","hbcd","16-bit","space=4");
   zdialog_add_widget(zd,"radio","samebpc","hbcd","no change","space=4");

   zdialog_add_widget(zd,"hbox","hbwh","dialog");
   zdialog_add_widget(zd,"label","labw","hbwh","Max. Width","space=5");
   zdialog_add_widget(zd,"zspin","maxww","hbwh","0|10000|1|1000","size=5");
   zdialog_add_widget(zd,"label","space","hbwh",0,"space=5");
   zdialog_add_widget(zd,"label","labh","hbwh","Height","space=5");
   zdialog_add_widget(zd,"zspin","maxhh","hbwh","0|10000|1|700","size=5");
   zdialog_add_widget(zd,"check","downsize","hbwh","downsize","space=12");
   zdialog_add_widget(zd,"check","upsize","hbwh","upsize","space=12");
   zdialog_add_widget(zd,"label","space","hbwh",0,"space=30");                   //  push back oversized entries
   zdialog_add_ttip(zd,"downsize","reduce to these limits if larger");
   zdialog_add_ttip(zd,"upsize","expand to these limits if smaller");

   zdialog_add_widget(zd,"hbox","hbopts","dialog");
   zdialog_add_widget(zd,"check","delete","hbopts","Delete Originals","space=3");
   zdialog_add_widget(zd,"check","copymeta","hbopts","Copy Metadata","space=5");

   snprintf(text,100,"%d image files selected",SFcount);                         //  show selected files count
   zdialog_stuff(zd,"fcount",text);

   zdialog_stuff(zd,"tif",0);
   zdialog_stuff(zd,"png",0);
   zdialog_stuff(zd,"jpg",0);
   zdialog_stuff(zd,"jpgqual",jpeg_def_quality);
   zdialog_stuff(zd,"sametype",1);                                               //  same file type

   zdialog_stuff(zd,"8-bit",0);
   zdialog_stuff(zd,"16-bit",0);
   zdialog_stuff(zd,"samebpc",1);                                                //  same bits/color

   zdialog_stuff(zd,"downsize",0);                                               //  no size change
   zdialog_stuff(zd,"upsize",0);
   zdialog_stuff(zd,"delete",0);                                                 //  delete originals - no
   zdialog_stuff(zd,"copymeta",1);                                               //  copy metadata - yes

   *newloc = 0;
   oldfiles = newfiles = 0;
   Noldnew = 0;

   zdialog_load_inputs(zd);                                                      //  preload prior user inputs
   zdialog_run(zd,batch_convert_dialog_event,"parent");                          //  run dialog
   zstat = zdialog_wait(zd);                                                     //  wait for completion
   zdialog_free(zd);
   if (zstat != 1) goto cleanup;                                                 //  canceled
   if (! SFcount) goto cleanup;

   free_resources();                                                             //  no curr. file

   if (Fdelete) {
      cc = SFcount * sizeof(ch *);                                               //  input files are to be deleted:
      oldfiles = (ch **) zmalloc(cc,"batch convert");                            //    reserve space to hold list of
      newfiles = (ch **) zmalloc(cc,"batch convert");                            //    old/new filespecs to update albums
   }

   zdpop = popup_report_open("Processing files",Mwin,600,300,0,0,0,"X",0);       //  log report

   Funcbusy(+1);                                                                 //  24.10

   for (ii = 0; ii < SFcount; ii++)                                              //  loop selected files
   {
      zmainloop();                                                               //  keep GTK alive

      if (! zdialog_valid(zdpop)) break;                                         //  report canceled

      infile = SelFiles[ii];                                                     //  input file

      popup_report_write2(zdpop,0,"\n");
      popup_report_write2(zdpop,0,"%s \n",infile);                               //  log each input file

      if (image_file_type(infile) != IMAGE) {
         popup_report_write2(zdpop,0,"*** invalid file \n");
         continue;
      }

      parsefile(infile,&inloc,&inname,&inext);                                   //  parse folder, filename, .ext
      if (! inloc || ! inname || ! inext) continue;

      outloc = zstrdup(inloc,"batch convert");                                   //  initial output = input file
      outname = zstrdup(inname,"batch convert");
      outext = zstrdup(inext,"batch convert",4);

      cc = strlen(outloc) - 1;                                                   //  remove trailing '/'
      if (outloc[cc] == '/') outloc[cc] = 0;

      if (*newname) {
         zfree(outname);
         outname = zstrdup(newname,"batch convert");                             //  may contain $-plugins
      }

      if (Fnewtext) {
         tempname = zstrdup(outname,"batch convert",100);
         cc = strlen(outname) + 100;
         repl_1str(outname,tempname,cc,text1,text2);                             //  replace text1 (if present) with text2
         zfree(outname);
         outname = tempname;
      }

      if (Fplugname)                                                             //  insert old file name
      {
         cc = strlen(outname) - 8 + strlen(inname);
         if (cc < 1) cc = 1;
         tempname = zstrdup(outname,"batch convert",cc);
         cc += strlen(outname);
         repl_1str(outname,tempname,cc,"$oldname",inname);                       // ...$oldname...  >>  ...inname...
         zfree(outname);
         outname = tempname;
      }

      if (Fplugdate)                                                             //  insert meta date
      {
         xxrec = get_xxrec(infile);                                              //  get photo date, yyyymmddhhmmdd

         if (strmatch(xxrec->pdate,"null")) {
            popup_report_write2(zdpop,0,"no photo date, skipped \n");
            zfree(outloc);
            zfree(outname);
            zfree(outext);
            continue;
         }

         strncpy0(plugyyyy,xxrec->pdate,5);                                      //  yyyy
         strncpy0(plugmm,xxrec->pdate+4,3);                                      //  mm
         strncpy0(plugdd,xxrec->pdate+6,3);                                      //  dd
         tempname = zstrdup(outname,"batch convert",8);
         cc = strlen(outname) + 8;
         repl_Nstrs(outname,tempname,cc,"$yyyy",plugyyyy,"$mm",plugmm,"$dd",plugdd,null);
         zfree(outname);
         outname = tempname;
      }

      if (Fplugseq)                                                              //  insert sequence number
      {
         pp = strcasestr(outname,"$s");                                          //  find $s... in output name
         if (pp) {
            for (cc = 1; pp[cc] == pp[1] && cc < 6; cc++);                       //  length of "$s...s"  2-6 chars.
            strncpy0(seqplug,pp,cc+1);
            jj = baseseq + ii * addseq;                                          //  new sequence number
            snprintf(seqnum,8,"%0*d",cc-1,jj);                                   //  1-5 chars.
            tempname = zstrdup(outname,"batch convert",8);
            cc = strlen(outname) + 8;
            repl_1str(outname,tempname,cc,seqplug,seqnum);                       //  ...$ssss...  >>  ...1234...
            zfree(outname);
            outname = tempname;
         }
      }

      if (*newloc) {                                                             //  new location was given
         zfree(outloc);
         outloc = zstrdup(newloc,"batch convert");
      }

      if (Fsametype) {                                                           //  new .ext = existing .ext
         if (strcasestr(".jpg .jpeg .png .tif .tiff",inext))
            strcpy(outext,inext);
         else strcpy(outext,".jpg");                                             //  other >> .jpg
      }
      else strcpy(outext,newext);                                                //  new .ext was given

      cc = strlen(outloc) + strlen(outname) + strlen(outext) + 4;                //  construct output file name
      outfile = (ch *) zmalloc(cc,"batch convert");
      snprintf(outfile,cc,"%s/%s%s",outloc,outname,outext);

      Fjpeg = 0;
      if (strmatch(outext,".jpg")) Fjpeg = 1;

      zfree(outloc);
      zfree(outname);
      zfree(outext);

      pxmin = PXM_load(infile,0);                                                //  read input file
      if (! pxmin) {
         popup_report_write2(zdpop,1,"file type not supported: %s \n",inext);
         zfree(outfile);
         continue;
      }

      popup_report_write2(zdpop,0,"%s \n",outfile);                              //  log each output file

      if (*newloc) {
         if (regfile(outfile)) {                                                 //  check if file exists in new location
            popup_report_write2(zdpop,1,"output file exists \n");
            zfree(outfile);
            continue;
         }
      }

      outbpc = f_load_bpc;                                                       //  input file bits/color
      outww = pxmin->ww;                                                         //  input file size
      outhh = pxmin->hh;

      if (! Fsamebpc) outbpc = newbpc;                                           //  new bits/color
      if (Fjpeg) outbpc = 8;                                                     //  if jpeg, force 8 bits/color

      if (Fdownsize)                                                             //  downsize larger images
      {
         wscale = hscale = 1.0;
         if (outww > maxww) wscale = 1.0 * maxww / outww;                        //  compute new size
         if (outhh > maxhh) hscale = 1.0 * maxhh / outhh;
         if (wscale < hscale) scale = wscale;                                    //  scale < 1
         else scale = hscale;
         if (scale < 1.0) {
            outww = outww * scale + 0.5;                                         //  round
            outhh = outhh * scale + 0.5;
            pxmout = PXM_rescale(pxmin,outww,outhh);                             //  rescaled output file
            PXM_free(pxmin);
            pxmin = 0;
         }
      }

      if (Fupsize && pxmin)                                                      //  upsize smaller images
      {
         wscale = hscale = 1.0;
         if (outww < maxww) wscale = 1.0 * maxww / outww;                        //  compute new size
         if (outhh < maxhh) hscale = 1.0 * maxhh / outhh;
         if (wscale < hscale) scale = wscale;                                    //  scale > 1
         else scale = hscale;
         if (scale > 1.0) {
            outww = outww * scale + 0.5;                                         //  round
            outhh = outhh * scale + 0.5;
            pxmout = PXM_rescale(pxmin,outww,outhh);                             //  rescaled output file
            PXM_free(pxmin);
            pxmin = 0;
         }
      }

      if (pxmin) {                                                               //  no size change
         pxmout = pxmin;
         pxmin = 0;
      }

      pp1 = strrchr(outfile,'/');                                                //  get filename.ext
      if (pp1) pp1++;
      else pp1 = outfile;
      snprintf(tempfile,300,"%s/%s",temp_folder,pp1);                            //  temp file for meta copy

      err = PXM_save(pxmout,tempfile,outbpc,jpeg_quality,0);                     //  write output image to temp file
      if (err) {
         popup_report_write2(zdpop,1,"cannot create new file \n");
         zfree(outfile);
         PXM_free(pxmout);
         continue;
      }

      if (Fcopymeta) {                                                           //  copy meta if requested
         err = meta_copy(infile,tempfile,0,0,0);
         if (err) popup_report_write2(zdpop,1,"metadata update error \n");
      }

      err = cp_copy(tempfile,outfile);                                           //  copy tempfile to output file
      if (err) popup_report_write2(zdpop,1,"%s \n",strerror(err));

      remove(tempfile);                                                          //  remove tempfile

      Fdelete2 = 0;                                                              //  figure out if input file can be deleted
      if (Fdelete) Fdelete2 = 1;                                                 //  user says yes
      if (err) Fdelete2 = 0;                                                     //  not if error
      if (strmatch(infile,outfile)) Fdelete2 = 0;                                //  not if overwritten by output

      if (Fdelete2)                                                              //  delete input file
         err = f_remove(infile,"delete");                                        //  file/index/thumb/gallery

      if (! err) {
         load_filemeta(outfile);                                                 //  update image index for output file
         update_image_index(outfile);
      }

      if (Fdelete2) {                                                            //  if input file was deleted,
         oldfiles[Noldnew] = zstrdup(infile,"batch convert");                    //    mark for updating albums
         newfiles[Noldnew] = zstrdup(outfile,"batch convert");
         Noldnew++;
      }

      zfree(outfile);
      PXM_free(pxmout);
   }

   Funcbusy(-1);

   if (! zdialog_valid(zdpop)) {
      Plog(0,"*** report canceled \n");
      goto cleanup;
   }

   popup_report_write2(zdpop,0,"\n *** COMPLETED \n");
   popup_report_bottom(zdpop);

cleanup:

   if (Noldnew) {
      for (ii = 0; ii < Noldnew; ii++) {
         zfree(oldfiles[ii]);
         zfree(newfiles[ii]);
      }
      zfree(oldfiles);
      zfree(newfiles);
      Noldnew = 0;
   }

   gallery(navi::galleryname,"init",0);                                          //  refresh file list
   gallery(0,"sort",-2);                                                         //  recall sort and position
   gallery(0,"paint",-1);                                                        //  repaint from same position

   Fblock(0);
   return;
}


//  dialog event and completion callback function

int batch_convert_dialog_event(zdialog *zd, ch *event)
{
   using namespace batch_convert;

   ch          *pp, *ploc, badplug[20];
   ch          countmess[80];
   int         ii, cc, yn, err;

   if (strmatch(event,"files"))                                                  //  select images to convert
   {
      zdialog_show(zd,0);                                                        //  hide parent dialog
      select_files(0,1);                                                         //  get list of files to convert          24.20
      zdialog_show(zd,1);

      snprintf(countmess,80,"%d image files selected",SFcount);                  //  update dialog
      zdialog_stuff(zd,"fcount",countmess);
   }

   if (strmatch(event,"browse")) {
      zdialog_fetch(zd,"newloc",newloc,500);
      ploc = zgetfile("Select folder",MWIN,"folder",newloc);                     //  new location browse
      if (! ploc) return 1;
      zdialog_stuff(zd,"newloc",ploc);
      zfree(ploc);
   }

   if (zstrstr("tif png jpg sametype",event)) {
      zdialog_stuff(zd,"tif",0);
      zdialog_stuff(zd,"png",0);
      zdialog_stuff(zd,"jpg",0);
      zdialog_stuff(zd,"sametype",0);
      zdialog_stuff(zd,event,1);
   }

   if (zstrstr("8-bit 16-bit samebpc",event)) {
      zdialog_stuff(zd,"8-bit",0);
      zdialog_stuff(zd,"16-bit",0);
      zdialog_stuff(zd,"samebpc",0);
      zdialog_stuff(zd,event,1);
   }

   zdialog_fetch(zd,"jpg",ii);                                                   //  if jpeg, force 8 bits/color
   if (ii) {
      zdialog_stuff(zd,"16-bit",0);
      zdialog_stuff(zd,"samebpc",0);
      zdialog_stuff(zd,"8-bit",1);
   }

   //  wait for dialog completion via [proceed] button

   if (zd->zstat != 1) return 1;
   zd->zstat = 0;                                                                //  keep active until inputs OK

   zdialog_fetch(zd,"text1",text1,100);                                          //  text within file name
   zdialog_fetch(zd,"text2",text2,100);                                          //  replacement text
   zdialog_fetch(zd,"newname",newname,200);                                      //  new file name
   zdialog_fetch(zd,"baseseq",baseseq);                                          //  base sequence number
   zdialog_fetch(zd,"addseq",addseq);                                            //  sequence number adder
   zdialog_fetch(zd,"newloc",newloc,500);                                        //  new location (folder)
   zdialog_fetch(zd,"maxww",maxww);                                              //  new max width
   zdialog_fetch(zd,"maxhh",maxhh);                                              //  new max height
   zdialog_fetch(zd,"downsize",Fdownsize);                                       //  downsize checkbox
   zdialog_fetch(zd,"upsize",Fupsize);                                           //  upsize checkbox

   zdialog_fetch(zd,"jpgqual",jpeg_quality);                                     //  jpeg quality
   zdialog_fetch(zd,"delete",Fdelete);                                           //  delete originals
   zdialog_fetch(zd,"copymeta",Fcopymeta);                                       //  copy metadata

   zdialog_fetch(zd,"sametype",Fsametype);
   zdialog_fetch(zd,"jpg",ii);
   if (ii) strcpy(newext,".jpg");
   zdialog_fetch(zd,"tif",ii);
   if (ii) strcpy(newext,".tif");
   zdialog_fetch(zd,"png",ii);
   if (ii) strcpy(newext,".png");

   zdialog_fetch(zd,"samebpc",Fsamebpc);
   zdialog_fetch(zd,"8-bit",ii);
   if (ii) newbpc = 8;
   zdialog_fetch(zd,"16-bit",ii);
   if (ii) newbpc = 16;

   if (! SFcount) {
      zmessageACK(Mwin,"no files selected");
      return 1;
   }

   Fnewtext = 0;
   if (*text1) Fnewtext = 1;                                                     //  replace text1 with text2 (may be null)

   Fplugdate = Fplugseq = Fplugname = 0;

   strTrim2(newname);
   if (! blank_null(newname))
   {
      if (Fnewtext) {
         zmessageACK(Mwin,"you cannot use new name and replace text together");
         return 1;
      }

      pp = newname;

      while ((pp = strchr(pp,'$')))
      {
         if (strmatchN(pp,"$yyyy",5)) Fplugdate = 1;                             //  $yyyy
         else if (strmatchN(pp,"$mm",3)) Fplugdate = 1;                          //  $mm
         else if (strmatchN(pp,"$dd",3)) Fplugdate = 1;                          //  $dd
         else if (strmatchN(pp,"$s",2)) Fplugseq = 1;                            //  $s...s   (sequence number cc)
         else if (strmatchN(pp,"$oldname",8)) Fplugname = 1;                     //  $oldname
         else {
            for (cc = 0; pp[cc] > ' ' && cc < 20; cc++);
            strncpy0(badplug,pp,cc);
            zmessageACK(Mwin,"invalid plugin: %s",badplug);
            return 1;
         }
         pp++;
      }
   }

   if (! blank_null(newname) && ! Fplugname && ! Fplugseq) {
      zmessageACK(Mwin,"you must use either $s or $oldname");
      return 1;
   }

   if (Fplugseq && (baseseq < 1 || addseq < 1)) {
      zmessageACK(Mwin,"$s plugin needs base and adder");
      return 1;
   }

   if (! Fplugseq && (baseseq > 0 || addseq > 0)) {
      zmessageACK(Mwin,"base and adder need $s plugin");
      return 1;
   }

   strTrim2(newloc);                                                             //  check location
   if (! blank_null(newloc)) {
      cc = strlen(newloc) - 1;
      if (newloc[cc] == '/') newloc[cc] = 0;                                     //  remove trailing '/'
      err = check_create_dir(newloc);                                            //  create if needed
      if (err) return 1;
   }

   if (! Fdownsize && ! Fupsize) {                                               //  if no downsize or upsize wanted,
      zdialog_stuff(zd,"maxww",0);                                               //    clear max. width and height values
      zdialog_stuff(zd,"maxhh",0);
   }

   else {                                                                        //  if either downsize/upsize wanted,
      if (maxww < 20 || maxhh < 20                                               //    check max. width and height values
          || maxww > wwhh_limit1 || maxhh > wwhh_limit1
          || maxww * maxhh > wwhh_limit2) {
         zmessageACK(Mwin,"max. width or height is not reasonable");
         return 1;
      }
   }

   Freplace = 0;
   if (*newname <= ' ' && *newloc <= ' ' && Fsametype)
      Freplace = 1;

   if (Freplace && Fdelete) {
      zmessageACK(Mwin,"delete originals specified but no new name given");
      return 1;
   }

   /**   Convert NN image files                    CF
           Replace text: xxxx --> yyyy             RT
           Rename to xxxxxxx                       RN
           Convert to .ext  N-bits/color           CX  CXa
           Downsize within NNxNN                   DZ
           Upsize within NNxNN                     UZ  UZa
           Output to /.../...                      OP
           Copy Metadata                           CM
           *** Delete Originals ***                DO
           *** Replace Originals ***               RO
         PROCEED?                                  PR
   **/

   ch    messCF[60], messRN[100], messRT[230], messCX[60], messCXa[60],
         messDZ[60], messDZa[60], messOP[550], messCM[80], messDO[60],
         messRO[60], messPR[40];
   ch    warnmess[1000];

   *messCF = *messRN = *messRT = *messCX = *messCXa = *messDZ = *messDZa
          = *messOP = *messCM = *messDO = *messRO = *messPR = 0;

   snprintf(messCF,60,"Convert %d image files",SFcount);
   if (Fnewtext) snprintf(messRT,230,"\n  Replace text: %s  →  %s",text1,text2);
   if (*newname) snprintf(messRN,100,"\n  %s %s","Rename to",newname);
   if (! Fsametype) snprintf(messCX,60,"\n  %s %s","Convert to",newext);
   if (! Fsamebpc) snprintf(messCXa,60,"\n  %d-bits/color",newbpc);
   if (Fdownsize) snprintf(messDZ,60,"\n  %s %dx%d","Downsize within",maxww,maxhh);
   if (Fupsize) snprintf(messDZa,60,"\n  %s %dx%d","Upsize within",maxww,maxhh);
   if (*newloc) snprintf(messOP,550,"\n  %s  %s","Output to",newloc);
   if (Fcopymeta) { strcat(messCM,"\n  Copy Metadata"); strcat(messCM,"  "); }
   if (Fdelete) snprintf(messDO,60,"\n  %s","*** Delete Originals ***");
   if (Freplace) snprintf(messRO,60,"\n  %s","*** Replace Originals ***");
   snprintf(messPR,40,"\n\n%s","PROCEED?");

   snprintf(warnmess,1000,"%s %s %s %s %s %s %s %s %s %s %s %s",
            messCF, messRT, messRN, messCX, messCXa, messDZ, messDZa, messOP,
            messCM, messDO, messRO, messPR);

   yn = zmessageYN(Mwin,warnmess);
   if (! yn) return 1;

   zd->zstat = 1;                                                                //  [proceed]
   return 1;
}


/********************************************************************************/

//  Move selected files to a new location (Fotocx indexed)

namespace batch_copy_move_names
{
   ch       newloc[500];                                                         //  destination folder
   int      Fdelete;                                                             //  delete originals
}


//  menu function

void m_batch_copy_move(GtkWidget *, ch *)
{
   using namespace batch_copy_move_names;

   int  batch_copy_move_dialog_event(zdialog *zd, ch *event);

   zdialog     *zd, *zdpop;
   int         ii, cc, err;
   int         zstat;
   ch          *pp, text[100];
   ch          *infile, *outfile;
   ch          **oldfiles, **newfiles;
   int         Noldnew;

   F1_help_topic = "batch copy/move";

   Plog(1,"m_batch_copy_move \n");
   
   if (Findexvalid == 0) {
      zmessageACK(Mwin,"image index disabled");                                  //  no image index
      return;
   }

   if (Fblock("batch copy/move")) return;

/***
       ___________________________________________________________
      |                    Batch Copy/Move                        |
      |                                                           |
      |  [Select Files]  N files selected                         |
      |                                                           |
      |  New Location [_______________________________] [browse]  |
      |                                                           |
      |  [x] Delete Originals                                     |
      |                                                           |
      |                                             [Proceed] [X] |
      |___________________________________________________________|

***/

   zd = zdialog_new("Batch Copy/Move",Mwin,"Proceed"," X ",null);

   zdialog_add_widget(zd,"hbox","hbf","dialog",0,"space=5");
   zdialog_add_widget(zd,"button","files","hbf","Select Files","space=5");
   zdialog_add_widget(zd,"label","fcount","hbf","no files selected","space=10");

   zdialog_add_widget(zd,"hbox","hbloc","dialog");
   zdialog_add_widget(zd,"label","labloc","hbloc","New Location","space=5");
   zdialog_add_widget(zd,"zentry","newloc","hbloc",0,"expand");
   zdialog_add_widget(zd,"button","browse","hbloc","Browse","space=5");

   zdialog_add_widget(zd,"hbox","hbdel","dialog");
   zdialog_add_widget(zd,"check","delete","hbdel","Delete Originals","space=3");

   snprintf(text,100,"%d image files selected",SFcount);                         //  show selected files count
   zdialog_stuff(zd,"fcount",text);

   zdialog_stuff(zd,"delete",0);                                                 //  delete originals - no

   *newloc = 0;                                                                  //  no new location

   oldfiles = newfiles = 0;                                                      //  list of old/new files
   Noldnew = 0;                                                                  //    for album updates

   zdialog_load_inputs(zd);                                                      //  preload prior user inputs
   zdialog_run(zd,batch_copy_move_dialog_event,"parent");                        //  run dialog
   zstat = zdialog_wait(zd);                                                     //  wait for completion
   zdialog_free(zd);
   if (zstat != 1) goto cleanup;                                                 //  canceled
   if (! SFcount) goto cleanup;                                                  //  no files selected

   free_resources();                                                             //  no curr. file

   if (Fdelete) {
      cc = SFcount * sizeof(ch *);                                               //  input files are to be deleted:
      oldfiles = (ch **) zmalloc(cc,"batch copy/move");                          //    reserve space to hold list of
      newfiles = (ch **) zmalloc(cc,"batch copy/move");                          //    old/new filespecs to update albums
   }

   cc = strlen(newloc);                                                          //  output location
   if (newloc[cc-1] == '/') newloc[cc-1] = 0;                                    //  remove trailing '/'

   zdpop = popup_report_open("Processing files",Mwin,600,300,0,0,0,"X",0);       //  log report

   Funcbusy(+1);                                                                 //  24.10

   for (ii = 0; ii < SFcount; ii++)                                              //  loop selected files
   {
      zmainloop();                                                               //  keep GTK alive

      if (! zdialog_valid(zdpop)) break;                                         //  report canceled

      infile = SelFiles[ii];                                                     //  input file

      popup_report_write2(zdpop,0,"\n");
      popup_report_write2(zdpop,0,"%s \n",infile);                               //  log each input file

      if (image_file_type(infile) != IMAGE) {
         popup_report_write2(zdpop,0,"*** invalid file \n");
         continue;
      }

      pp = strrchr(infile,'/');                                                  //  /filename.ext
      cc = strlen(newloc) + strlen(pp) + 2;
      outfile = (ch *) zmalloc(cc,"batch copy/move");
      strcpy(outfile,newloc);                                                    //  /newloc/.../filename.ext
      strcat(outfile,pp);

      popup_report_write2(zdpop,0,"%s \n",outfile);                              //  log each output file

      if (regfile(outfile)) {                                                    //  check if file exists in new location
         popup_report_write2(zdpop,1,"%s \n","output file exists");
         zfree(outfile);
         continue;
      }

      err = cp_copy(infile,outfile);                                             //  copy infile to outfile
      if (err) {
         popup_report_write2(zdpop,1,"%s \n",strerror(err));                     //  error, do nothing
         zfree(outfile);
         continue;
      }

      load_filemeta(outfile);                                                    //  update image index for output file
      update_image_index(outfile);

      if (Fdelete)                                                               //  delete input file
      {
         err = f_remove(infile,"delete");                                        //  file/index/thumb/gallery

         oldfiles[Noldnew] = zstrdup(infile,"batch copy/move");                  //  mark for updating albums
         newfiles[Noldnew] = zstrdup(outfile,"batch copy/move");
         Noldnew++;
      }

      zfree(outfile);
   }

   Funcbusy(-1);

   if (! zdialog_valid(zdpop)) {
      Plog(0,"*** report canceled \n");
      goto cleanup;
   }

   if (Noldnew) {                                                                //  update albums for renamed/moved files
      popup_report_write2(zdpop,0,"%s \n","updating albums ...");
      album_purge_replace("ALL",Noldnew,oldfiles,newfiles);
   }

   popup_report_write2(zdpop,0,"\n *** %s \n","COMPLETED");
   popup_report_bottom(zdpop);

cleanup:

   if (Noldnew) {
      for (ii = 0; ii < Noldnew; ii++) {
         zfree(oldfiles[ii]);
         zfree(newfiles[ii]);
      }
      if (oldfiles) zfree(oldfiles);
      if (newfiles) zfree(newfiles);
      Noldnew = 0;
   }

   gallery(navi::galleryname,"init",0);                                          //  refresh file list
   gallery(0,"sort",-2);                                                         //  recall sort and position
   gallery(0,"paint",-1);                                                        //  repaint from same position

   Fblock(0);
   return;
}


//  dialog event and completion callback function

int batch_copy_move_dialog_event(zdialog *zd, ch *event)
{
   using namespace batch_copy_move_names;

   ch          countmess[80];
   ch          *ploc;
   int         cc, yn, err;

   if (strmatch(event,"files"))                                                  //  select images to convert
   {
      zdialog_show(zd,0);                                                        //  hide parent dialog
      select_files(0,1);                                                         //  get list of files to copy             24.20
      zdialog_show(zd,1);

      snprintf(countmess,80,"%d image files selected",SFcount);                  //  update dialog
      zdialog_stuff(zd,"fcount",countmess);
   }

   if (strmatch(event,"browse")) {
      zdialog_fetch(zd,"newloc",newloc,500);
      ploc = zgetfile("Select folder",MWIN,"folder",newloc);                     //  new location browse
      if (! ploc) return 1;
      zdialog_stuff(zd,"newloc",ploc);
      zfree(ploc);
   }

   if (zd->zstat != 1) return 1;                                                 //  not [proceed]

   zd->zstat = 0;                                                                //  keep active until inputs OK

   if (! SFcount) {
      zmessageACK(Mwin,"no files selected");
      return 1;
   }

   zdialog_fetch(zd,"newloc",newloc,500);
   zdialog_fetch(zd,"delete",Fdelete);                                           //  delete originals

   strTrim2(newloc);                                                             //  check location
   cc = strlen(newloc) - 1;
   if (newloc[cc] == '/') newloc[cc] = 0;                                        //  remove trailing '/'
   err = check_create_dir(newloc);                                               //  create if needed
   if (err) return 1;

   /**
         Move NN image files                       0
         New Location: /.../...                    1
         *** Delete Originals ***                  2
         PROCEED?                                  3
   **/

   ch    mess0[60], mess1[600], mess2[60], mess3[40];
   ch    warnmess[800];

   *mess0 = *mess1 = *mess2 = *mess3 = 0;

   snprintf(mess0,60,"Move %d image files",SFcount);
   snprintf(mess1,600,"\n New Location: %s",newloc);
   if (Fdelete) snprintf(mess2,60,"\n *** Delete Originals ***");
   snprintf(mess3,40,"\n PROCEED?");

   snprintf(warnmess,800,"%s %s %s %s",mess0,mess1,mess2,mess3);

   yn = zmessageYN(Mwin,warnmess);
   if (! yn) return 1;

   zd->zstat = 1;                                                                //  [proceed]
   return 1;
}


/********************************************************************************/

//  Batch upright image files.
//  Look for files rotated 90Ëš (according to metadata) and upright them.

ch     **bup_filelist = 0;
int      bup_filecount = 0;
int      bup_allfiles;

void m_batch_upright(GtkWidget *, ch *)
{
   int  batch_upright_dialog_event(zdialog *zd, ch *event);

   zdialog        *zd, *zdpop;
   int            zstat;
   ch             *infile, *newfile, *delfile;
   ch             *pp, *ppv[1], text[100];
   int            ii, cc, err, yn;
   int            angle, mirror;
   ch             *metakey[1] = { meta_orientation_key };
   ch             orient;

   F1_help_topic = "batch upright";

   Plog(1,"m_batch_upright \n");

   if (Findexvalid == 0) {
      zmessageACK(Mwin,"image index disabled");                                  //  no image index
      return;
   }
   
   if (Fblock("batch upright")) return;

/***
       ___________________________________
      |       Batch Upright               |
      |                                   |
      |  [Select Files]  N files selected |
      |  [x] Survey all files             |
      |                                   |
      |                     [Proceed] [X] |
      |___________________________________|

***/

   zd = zdialog_new("Batch Upright",Mwin,"Proceed"," X ",null);

   zdialog_add_widget(zd,"hbox","hbf","dialog",0,"space=5");
   zdialog_add_widget(zd,"button","files","hbf","Select Files","space=5");
   zdialog_add_widget(zd,"label","fcount","hbf","no files selected","space=10");
   zdialog_add_widget(zd,"hbox","hbaf","dialog");
   zdialog_add_widget(zd,"check","allfiles","hbaf","Survey all files","space=5");

   snprintf(text,100,"%d image files selected",SFcount);                         //  show selected files count
   zdialog_stuff(zd,"fcount",text);

   bup_filelist = 0;
   bup_filecount = 0;

   zdialog_run(zd,batch_upright_dialog_event,"parent");                          //  run dialog
   zstat = zdialog_wait(zd);                                                     //  wait for completion
   zdialog_free(zd);
   if (zstat != 1) goto cleanup;                                                 //  canceled
   if (! bup_allfiles && ! bup_filecount) goto cleanup;                          //  nothing selected

   free_resources();                                                             //  no curr. file

   if (bup_allfiles) {                                                           //  "survey all files" selected
      cc = Nxxrec * sizeof(ch *);
      bup_filelist = (ch **) zmalloc(cc,"batch upright");
      for (ii = 0; ii < Nxxrec; ii++)
         bup_filelist[ii] = zstrdup(xxrec_tab[ii]->file,"batch upright");
      bup_filecount = Nxxrec;
   }

   for (ii = 0; ii < bup_filecount; ii++) {                                      //  warn about file type changes
      pp = strrchr(bup_filelist[ii],'.');
      if (pp && strcasestr(".jp2 .heic .avif .webp",pp)) break;
   }
   if (ii < bup_filecount) {
      yn = zmessageYN(Mwin,"files types: .jp2 .heic .avif .webp \n"
                           "will become: .jpg    CONTINUE?");
      if (! yn) goto cleanup;
   }

   zdpop = popup_report_open("Processing files",Mwin,500,200,0,0,0,"X",0);       //  log report

   Funcbusy(+1);                                                                 //  24.10

   for (ii = 0; ii < bup_filecount; ii++)                                        //  loop selected files
   {
      zmainloop();                                                               //  keep GTK alive

      if (! zdialog_valid(zdpop)) break;                                         //  report canceled

      infile = bup_filelist[ii];                                                 //  input file
      popup_report_write2(zdpop,0,"%s \n",infile);                               //  log each output file

      if (image_file_type(infile) != IMAGE) {
         popup_report_write2(zdpop,0,"*** invalid file \n");
         continue;
      }

      meta_get1(infile,(ch **) metakey,ppv,1);                                   //  get metadata Orientation
      if (! ppv[0]) continue;
      orient = *ppv[0];
      zfree(ppv[0]);
      if (orient < '2' || orient > '8') continue;                                //  not rotated

      angle = mirror = 0;

      if (orient == '2') { angle = 0; mirror = 1; }                              //  horizontal mirror
      if (orient == '3') { angle = 180; mirror = 0; }                            //  rotate 180
      if (orient == '4') { angle = 0; mirror = 2; }                              //  vertical mirror
      if (orient == '5') { angle = 90; mirror = 1; }                             //  rotate 90 + horizontal mirror
      if (orient == '6') { angle = 90; mirror = 0; }                             //  rotate 90
      if (orient == '7') { angle = 270; mirror = 1; }                            //  rotate 270 + horizontal mirror
      if (orient == '8') { angle = 270; mirror = 0; }                            //  rotate 270

      err = f_open(infile);
      if (err) {
         popup_report_write2(zdpop,0,"*** cannot open input file");
         continue;
      }

      E0pxm = PXM_load(curr_file,0);                                             //  load poss. 16-bit image
      if (! E0pxm) {
         popup_report_write2(zdpop,0,"*** cannot read input file");
         continue;
      }

      E3pxm = PXM_upright(E0pxm,angle,mirror);                                   //  do rotate/mirror

      PXM_free(E0pxm);
      E0pxm = E3pxm;
      E3pxm = 0;

      if (strcasestr("jp2 heic avif webp",curr_file_type)) {                     //  save these types as .jpg
         newfile = zstrdup(curr_file,"batch_upright",16);
         delfile = zstrdup(curr_file,"batch_upright");
         pp = strrchr(newfile,'.');
         strcpy(pp,"-upright.jpg");
         Fupright = 1;                                                           //  mark uprighted (for metadata update)
         f_save(newfile,"jpg",8,0,1);                                            //  make .jpg duplicate
         f_open(newfile);                                                        //  show uprighted file
         remove(delfile);
         zfree(newfile);
         zfree(delfile);
      }
      else {
         Fupright = 1;                                                           //  mark uprighted (for metadata update)
         f_save(curr_file,curr_file_type,curr_file_bpc,0,1);                     //  replace file
         f_open(curr_file);
      }
   }

   Funcbusy(-1);

   if (! zdialog_valid(zdpop)) {
      Plog(0,"*** report canceled \n");
      goto cleanup;
   }

   popup_report_write2(zdpop,0,"\n *** COMPLETED \n");
   popup_report_bottom(zdpop);

cleanup:

   if (bup_filecount) {                                                          //  free memory
      for (ii = 0; ii < bup_filecount; ii++)
         zfree(bup_filelist[ii]);
      zfree(bup_filelist);
      bup_filelist = 0;
      bup_filecount = 0;
   }

   gallery(curr_file,"init",0);

   Fblock(0);
   return;
}


//  dialog event and completion callback function

int batch_upright_dialog_event(zdialog *zd, ch *event)
{
   ch        countmess[80];
   int       ii;

   if (strmatch(event,"files"))                                                  //  select images to convert
   {
      if (bup_filecount) {
         for (ii = 0; ii < bup_filecount; ii++)                                  //  free prior list
            zfree(bup_filelist[ii]);
         zfree(bup_filelist);
         bup_filelist = 0;
         bup_filecount = 0;
      }

      zdialog_show(zd,0);                                                        //  hide parent dialog
      select_files(0,1);                                                         //  get new list                          24.20
      zdialog_show(zd,1);

      snprintf(countmess,80,"%d image files selected",SFcount);                  //  update dialog
      zdialog_stuff(zd,"fcount",countmess);
      zdialog_stuff(zd,"allfiles",0);

      if (! SFcount) return 1;

      bup_filelist = (ch **) zmalloc(SFcount * sizeof(ch *),"batch upright");    //  copy selected files
      for (ii = 0; ii < SFcount; ii++)
         bup_filelist[ii] = SelFiles[ii];
      bup_filecount = SFcount;
      SFcount = 0;
   }

   if (zd->zstat != 1) return 1;                                                 //  wait for [proceed]

   zdialog_fetch(zd,"allfiles",bup_allfiles);                                    //  get "survey all" option

   if (! bup_allfiles && ! bup_filecount) {                                      //  nothing selected
      zmessageACK(Mwin,"no files selected");
      zd->zstat = 0;                                                             //  keep dialog active
   }

   if (bup_allfiles && bup_filecount) {
      zmessageACK(Mwin,"cannot select both options");
      zd->zstat = 0;
   }

   return 1;
}


/********************************************************************************/

//  Batch delete or trash image files.

int      bdt_option;                                                             //  1/2 = delete/trash

void m_batch_deltrash(GtkWidget *, ch *)
{
   int  batch_deltrash_dialog_event(zdialog *zd, ch *event);

   zdialog     *zd, *zdpop;
   int         zstat, ii, nn, err;
   ch          *file, text[100];
   ch          **delfiles = 0;
   int         cc, Ndel = 0;

   F1_help_topic = "batch delete/trash";

   Plog(1,"m_batch_deltrash \n");

   if (Findexvalid == 0) {
      zmessageACK(Mwin,"image index disabled");                                  //  no image index
      return;
   }
   
   if (Fblock("batch delete/trash")) return;

/***
       ___________________________________
      |       Batch Delete/Trash          |
      |                                   |
      |  [Select Files]  N files selected |
      |  (o) delete    (o) trash          |
      |                                   |
      |                     [Proceed] [X] |
      |___________________________________|

***/

   zd = zdialog_new("Batch Delete/Trash",Mwin,"Proceed"," X ",null);
   zdialog_add_widget(zd,"hbox","hbf","dialog",0,"space=5");
   zdialog_add_widget(zd,"button","files","hbf","Select Files","space=5");
   zdialog_add_widget(zd,"label","fcount","hbf","no files selected","space=10");
   zdialog_add_widget(zd,"hbox","hbdt","dialog");
   zdialog_add_widget(zd,"label","labdel","hbdt","delete","space=5");
   zdialog_add_widget(zd,"radio","delete","hbdt",0);
   zdialog_add_widget(zd,"label","space","hbdt",0,"space=10");
   zdialog_add_widget(zd,"label","labtrash","hbdt","trash","space=5");
   zdialog_add_widget(zd,"radio","trash","hbdt",0);

   bdt_option = 2;

   snprintf(text,100,"%d image files selected",SFcount);                         //  show selected files count
   zdialog_stuff(zd,"fcount",text);

   zdialog_stuff(zd,"delete",0);
   zdialog_stuff(zd,"trash",1);

   zdialog_run(zd,batch_deltrash_dialog_event,"parent");                         //  run dialog
   zstat = zdialog_wait(zd);                                                     //  wait for completion

   zdialog_fetch(zd,"delete",bdt_option);                                        //  get delete/trash option
   if (! bdt_option) bdt_option = 2;

   zdialog_free(zd);
   if (zstat != 1) goto finish;                                                  //  canceled
   if (! SFcount) goto finish;

   free_resources();                                                             //  no curr. file

   cc = SFcount * sizeof(ch *);                                                  //  files to purge from albums
   delfiles = (ch **) zmalloc(cc,"batch deltrash");
   Ndel = 0;

   zdpop = popup_report_open("Processing files",Mwin,500,200,0,0,0,"X",0);       //  log report

   Funcbusy(+1);                                                                 //  24.10

   for (ii = 0; ii < SFcount; ii++)                                              //  loop selected files
   {
      zmainloop();                                                               //  keep GTK alive

      if (! zdialog_valid(zdpop)) break;                                         //  report canceled

      file = SelFiles[ii];                                                       //  log each file
      popup_report_write2(zdpop,0,"%s \n",file);

      if (! regfile(file)) {                                                     //  file exists?
         popup_report_write2(zdpop,1,"file not found \n");
         continue;
      }

      err = 0;
      if (bdt_option == 1)                                                       //  delete file
         err = f_remove(file,"delete");                                          //  file/index/thumb/gallery
      if (bdt_option == 2)                                                       //  move file to trash
         err = f_remove(file,"trash");
      if (err) {
         popup_report_write2(zdpop,1,"move to trash failed \n");                 //  gnome trash failed
         nn = zdialog_choose(Mwin,"parent","continue?","Yes","Quit",0);
         if (nn == 2) {                                                          //  quit
            zdpop->zstat = 1;
            break;
         }
      }

      delfiles[Ndel] = zstrdup(file,"batch deltrash");                           //  add to deleted files list
      Ndel++;
   }

   Funcbusy(-1);

   if (! zdialog_valid(zdpop)) {
      Plog(0,"*** report canceled \n");
      goto finish;
   }

   if (Ndel) {
      popup_report_write2(zdpop,0,"Purging deleted files from albums \n");       //  purge deleted files from albums
      album_purge_replace("ALL",Ndel,delfiles,0);
   }

   popup_report_write2(zdpop,0,"\n *** %s \n","COMPLETED");
   popup_report_bottom(zdpop);

finish:

   for (ii = 0; ii < Ndel; ii++)                                                 //  free memory
      zfree(delfiles[ii]);
   if (delfiles) zfree(delfiles);

   gallery(navi::galleryname,"init",0);                                          //  refresh file list
   gallery(0,"sort",-2);                                                         //  recall sort and position
   gallery(0,"paint",-1);                                                        //  repaint from same position

   Fblock(0);
   return;
}


//  dialog event and completion callback function

int batch_deltrash_dialog_event(zdialog *zd, ch *event)
{
   ch           countmess[80];
   int          ii;

   if (strmatch(event,"files"))                                                  //  select images to convert
   {
      zdialog_show(zd,0);                                                        //  hide parent dialog
      select_files(0,1);                                                         //  get files                             24.20
      zdialog_show(zd,1);

      snprintf(countmess,80,"%d image files selected",SFcount);                  //  update dialog
      zdialog_stuff(zd,"fcount",countmess);
   }

   if (strmatch(event,"delete")) {                                               //  delete radio button
      zdialog_fetch(zd,"delete",ii);
      if (ii) bdt_option = 1;
      zdialog_stuff(zd,"trash",0);
   }

   if (strmatch(event,"trash")) {                                                //  trash radio button
      zdialog_fetch(zd,"trash",ii);
      if (ii) bdt_option = 2;
      zdialog_stuff(zd,"delete",0);
   }

   if (zd->zstat != 1) return 1;                                                 //  wait for [proceed]

   if (! SFcount) {                                                              //  nothing selected
      zmessageACK(Mwin,"no files selected");
      zd->zstat = 0;                                                             //  keep dialog active
   }

   return 1;
}


/********************************************************************************/

//  convert multiple RAW files to tiff, jpeg, or png

namespace batch_raw
{
   ch       location[400], biasfile[400];
   ch       *filetype = 0;
   int      bpc, jpeg_quality;
   float    rescale;
   int      amount, thresh;
};


void m_batch_RAW(GtkWidget *, ch *menu)
{
   using namespace batch_raw;

   int  batch_raw_dialog_event(zdialog *zd, ch *event);

   zdialog     *zd, *zdpop;
   ch          *title = "Batch Convert RAW Files";
   ch          *rawfile, *tempfile, *outfile, *pp;
   ch          text[100];
   int         zstat, ii, err;
   FTYPE       ftype;
   int         cc, ww2, hh2;
   PXM         *pxm1, *pxm2;

   F1_help_topic = "batch raw";

   Plog(1,"m_batch_RAW \n");

   if (Findexvalid == 0) {
      zmessageACK(Mwin,"image index disabled");                                  //  no image index
      return;
   }

   if (Fblock("batch RAW")) return;
   
/***
       ________________________________________________________
      |              Batch Convert RAW Files                   |
      |                                                        |
      | [Select Files]  N image files selected                 |
      | output location [___________________________] [Browse] |
      | File Type: (o) tif  (o) png  (o) jpg [90] jpg quality  |
      | Color Depth: (o) 8-bit  (o) 16-bit                     |
      | Rescale  (o) 1.0  (o) 3/4  (o) 2/3  (o) 1/2  (o) 1/3   |
      |                                                        |
      |                                          [Proceed] [X] |
      |________________________________________________________|

***/

   zd = zdialog_new(title,Mwin,"Proceed"," X ",null);

   zdialog_add_widget(zd,"hbox","hb1","dialog",0,"space=2");
   zdialog_add_widget(zd,"button","files","hb1","Select Files","space=5");
   zdialog_add_widget(zd,"label","fcount","hb1","no files selected","space=10");

   zdialog_add_widget(zd,"hbox","hbout","dialog",0,"space=2");
   zdialog_add_widget(zd,"label","labout","hbout","output location","space=5");
   zdialog_add_widget(zd,"zentry","location","hbout",0,"space=5|expand");
   zdialog_add_widget(zd,"button","browselocation","hbout","Browse","space=5");

   zdialog_add_widget(zd,"hbox","hbft","dialog");
   zdialog_add_widget(zd,"label","labtyp","hbft","File Type","space=5");
   zdialog_add_widget(zd,"radio","tif","hbft","tif","space=4");
   zdialog_add_widget(zd,"radio","png","hbft","png","space=4");
   zdialog_add_widget(zd,"radio","jpg","hbft","jpg","space=2");
   zdialog_add_widget(zd,"zspin","jpgqual","hbft","10|100|1|90","size=3");
   zdialog_add_widget(zd,"label","labqual","hbft","jpg quality","space=6");

   zdialog_add_widget(zd,"hbox","hbcd","dialog");
   zdialog_add_widget(zd,"label","labcd","hbcd","Color Depth:","space=5");
   zdialog_add_widget(zd,"radio","8-bit","hbcd","8-bit","space=4");
   zdialog_add_widget(zd,"radio","16-bit","hbcd","16-bit","space=4");

   zdialog_add_widget(zd,"hbox","hbsize","dialog",0,"space=2");
   zdialog_add_widget(zd,"label","labsize","hbsize","Rescale","space=5");
   zdialog_add_widget(zd,"label","space","hbsize",0,"space=5");
   zdialog_add_widget(zd,"radio","1.0","hbsize","1.0","space=5");
   zdialog_add_widget(zd,"radio","3/4","hbsize","3/4","space=5");
   zdialog_add_widget(zd,"radio","2/3","hbsize","2/3","space=5");
   zdialog_add_widget(zd,"radio","1/2","hbsize","1/2","space=5");
   zdialog_add_widget(zd,"radio","1/3","hbsize","1/3","space=5");

   snprintf(text,100,"%d image files selected",SFcount);                         //  show selected files count
   zdialog_stuff(zd,"fcount",text);

   *location = 0;

   zdialog_stuff(zd,"tif",0);
   zdialog_stuff(zd,"png",0);
   zdialog_stuff(zd,"jpg",0);
   zdialog_stuff(zd,"jpgqual",jpeg_def_quality);
   zdialog_stuff(zd,"8-bit",0);
   zdialog_stuff(zd,"16-bit",0);

   zdialog_load_inputs(zd);                                                      //  get prior inputs if any
   zdialog_resize(zd,500,0);

   zdialog_run(zd,batch_raw_dialog_event,"parent");                              //  run dialog
   zstat = zdialog_wait(zd);                                                     //  wait for completion
   zdialog_free(zd);

   if (zstat != 1) goto cleanup;
   if (! SFcount) goto cleanup;
   
   free_resources();                                                             //  no current file                       24.30

   viewmode('F');

   zdpop = popup_report_open("Converting RAW files",Mwin,500,200,0,0,0,"X",0);   //  log report

   Funcbusy(+1);                                                                 //  24.10

   for (ii = 0; ii < SFcount; ii++)                                              //  loop all RAW files
   {
      zmainloop();

      if (! zdialog_valid(zdpop)) break;                                         //  report canceled

      rawfile = SelFiles[ii];                                                    //  filename.raw
      popup_report_write2(zdpop,0,"%s \n",rawfile);                              //  write to log window

      ftype = image_file_type(rawfile);
      if (ftype != RAW) {
         popup_report_write2(zdpop,1," unknown RAW file type \n");
         continue;
      }

      pxm1 = RAW_PXM_load(rawfile,Fraw_match_embed);
      if (! pxm1) continue;

      zmainloop();

      if (rescale < 1.0)                                                         //  rescale down if wanted
      {
         ww2 = rescale * pxm1->ww;
         hh2 = rescale * pxm1->hh;
         pxm2 = PXM_rescale(pxm1,ww2,hh2);
         PXM_free(pxm1);
         pxm1 = pxm2;

         if (! pxm1) {
            popup_report_write2(zdpop,1," rescale failed \n");
            continue;
         }
      }

      outfile = zstrdup(rawfile,"batch raw",5);                                  //  output file name = RAW file name

      pp = strrchr(outfile,'.');                                                 //  rename:  *.tif  *.jpg  *.png
      if (pp) strcpy(pp,filetype);

      err = PXM_save(pxm1,outfile,bpc,jpeg_quality,1);
      PXM_free(pxm1);

      if (err) {
         popup_report_write2(zdpop,1," file type conversion failed \n");
         zfree(outfile);
         continue;
      }

      err = meta_copy(rawfile,outfile,0,0,0);                                    //  copy metadata from RAW file
      if (err) popup_report_write2(zdpop,1," metadata update error \n");

      if (*location && ! samefolder(location,outfile)) {
         tempfile = zstrdup(outfile,"batch raw");                                //  copy to new location
         zfree(outfile);
         pp = strrchr(tempfile,'/');                                             //  /raw-location/filename.ext
         cc = strlen(pp);                                                        //               |
         outfile = zstrdup(location,"batch raw",cc+1);                           //               pp
         strcat(outfile,pp);                                                     //  /new-location/filename.ext
         err = cp_copy(tempfile,outfile);                                        //  copy to new location
         if (err) popup_report_write2(zdpop,1," %s \n",strerror(err));
         remove(tempfile);                                                       //  remove tempfile
         zfree(tempfile);
      }

      f_open(outfile,0,0,0);                                                     //  open converted file
      update_image_index(outfile);

      popup_report_write2(zdpop,0,"%s \n",outfile);                              //  write output file to log window
      zfree(outfile);
   }

   Funcbusy(-1);

   if (! zdialog_valid(zdpop)) {
      Plog(0,"*** report canceled \n");
      goto cleanup;
   }

   popup_report_write2(zdpop,0,"\n *** COMPLETED \n");
   popup_report_bottom(zdpop);

cleanup:                                                                         //  clean up and return

   gallery(navi::galleryname,"init",0);                                          //  refresh file list
   gallery(0,"sort",-2);                                                         //  recall sort and position
   gallery(0,"paint",-1);                                                        //  repaint from same position

   Fblock(0);
   return;
}


//  dialog event and completion callback function

int batch_raw_dialog_event(zdialog *zd, ch *event)
{
   using namespace batch_raw;

   int      ii, err, cc;
   ch       countmess[80], *ploc;

   if (strmatch(event,"files"))                                                  //  select images to convert
   {
      zdialog_show(zd,0);                                                        //  hide parent dialog
      select_files(0,1);                                                         //  get list of files to convert          24.20
      zdialog_show(zd,1);

      snprintf(countmess,80,"%d image files selected",SFcount);                  //  stuff count into dialog
      zdialog_stuff(zd,"fcount",countmess);
   }

   if (strmatch(event,"browselocation")) {                                       //  new location browse
      zdialog_fetch(zd,"location",location,400);
      if (*location <= ' ' && topfolders[0])
         strncpy0(location,topfolders[0],400);
      ploc = zgetfile("Select folder",MWIN,"folder",location);
      if (! ploc) return 1;
      zdialog_stuff(zd,"location",ploc);
      zfree(ploc);
   }

   if (zstrstr("tif png jpg",event)) {                                           //  gtk fails to do this correctly
      zdialog_stuff(zd,"tif",0);
      zdialog_stuff(zd,"png",0);
      zdialog_stuff(zd,"jpg",0);
      zdialog_stuff(zd,event,1);
   }

   if (zstrstr("8-bit 16-bit",event)) {                                          //  gtk fails to do this correctly
      zdialog_stuff(zd,"8-bit",0);
      zdialog_stuff(zd,"16-bit",0);
      zdialog_stuff(zd,event,1);
   }

   zdialog_fetch(zd,"jpg",ii);                                                   //  if jpeg, force 8 bits/color
   if (ii) {
      zdialog_stuff(zd,"16-bit",0);
      zdialog_stuff(zd,"8-bit",1);
   }

   //  wait for dialog completion via [proceed] button

   if (zd->zstat != 1) return 0;
   zd->zstat = 0;                                                                //  keep dialog active until inputs OK

   if (! SFcount) {                                                              //  no RAW files selected
      zmessageACK(Mwin,"no files selected");
      return 1;
   }

   zdialog_fetch(zd,"location",location,400);                                    //  output location
   strTrim2(location);
   if (! blank_null(location)) {
      cc = strlen(location) - 1;
      if (location[cc] == '/') location[cc] = 0;                                 //  remove trailing '/'
      err = check_create_dir(location);                                          //  create if needed
      if (err) return 1;
   }

   filetype = ".tif";
   zdialog_fetch(zd,"jpg",ii);
   if (ii) filetype = ".jpg";
   zdialog_fetch(zd,"tif",ii);
   if (ii) filetype = ".tif";
   zdialog_fetch(zd,"png",ii);
   if (ii) filetype = ".png";

   bpc = 8;
   zdialog_fetch(zd,"8-bit",ii);
   if (ii) bpc = 8;
   zdialog_fetch(zd,"16-bit",ii);
   if (ii) bpc = 16;

   zdialog_fetch(zd,"jpgqual",jpeg_quality);                                     //  jpeg quality

   rescale = 1.0;
   zdialog_fetch(zd,"1.0",ii);                                                   //  rescale option
   if (ii) rescale = 1.0;
   zdialog_fetch(zd,"3/4",ii);
   if (ii) rescale = 0.75;
   zdialog_fetch(zd,"2/3",ii);
   if (ii) rescale = 0.666667;
   zdialog_fetch(zd,"1/2",ii);
   if (ii) rescale = 0.50;
   zdialog_fetch(zd,"1/3",ii);
   if (ii) rescale = 0.333333;

   zdialog_fetch(zd,"amount",amount);
   zdialog_fetch(zd,"thresh",thresh);

   zd->zstat = 1;                                                                //  dialog complete
   return 1;
}


/********************************************************************************/

//  Add a small image file over selected host files (for author, copyright, etc.).
//  Added image position is designated % from host image top and left.
//  Added image width is designated % of host image width.
//  Added image can have transparency.

namespace batch_overlay
{
   ch       *ovfile = 0;                           //  overlay image file
   PXB      *ovfilepxb = 0;                        //  overlay file PXB
   int      pcttop, pctleft;                       //  overlay position, % from top, % from left, 1-99
   int      pctwidth;                              //  overlay width, % host image width, 5-95
   int      Fwinadj;                               //  flag, adjust overlay width for window size
   int      winww, winhh;                          //  window size (current or user input)
   int      Frepl, Fvers;                          //  flags, replace host files or make new versions
};


//  menu function

void m_batch_overlay(GtkWidget *, ch *)
{
   using namespace batch_overlay;

   int  batch_overlay_dialog_event(zdialog *zd, ch *event);

   zdialog     *zd, *zdpop;
   int         zstat;
   ch          *infile = 0, *outfile = 0;
   ch          text[100], *pp;
   int         ii, err;
   PXM         *infilepxm = 0;
   PXB         *ovpxb = 0;
   int         ovww, ovhh;
   int         ovorgx, ovorgy;
   int         px1, py1, px2, py2;
   uint8       *pix1;
   float       *pix2;
   float       f1, f2;
   float       winAR, infileAR;                                                  //  window and host image ww/hh ratios

   F1_help_topic = "batch overlay";

   Plog(1,"m_batch_overlay \n");

   if (Findexvalid == 0) {
      zmessageACK(Mwin,"image index disabled");                                  //  no image index
      return;
   }

   if (Fblock("batch overlay")) return;
   
/***
          __________________________________________________
         |               Batch Overlay Image                |
         |                                                  |
         |  [Select host image files]  no files selected    |           button: hostselect
         |  [Select overlay file]  no file selected         |           button: ovselect
         |  - - - - - - - - - - - - - - - - - - - - - - - - |
         |  Overlay position in host image:                 |
         |      % from top: [__]   % from left: [__]        |           zspin: pcttop  pctleft
         |  - - - - - - - - - - - - - - - - - - - - - - - - |
         |  Overlay width, % host image width: [__]         |           zspin: pctwidth
         |  [x] Make width constant for window size:        |           check: Fwinadj
         |      width [____]  height [____]   [_] refresh]  |           zspin: winww, winhh  zbutton: refresh
         |  - - - - - - - - - - - - - - - - - - - - - - - - |
         |  [x] Replace host files  [x] Make new versions   |           check: Frepl  check: Fvers
         |                                                  |
         |                                    [Proceed] [X] |
         |__________________________________________________|

***/

   zd = zdialog_new("Batch Overlay",Mwin,"Proceed"," X ",null);

   zdialog_add_widget(zd,"hbox","hbhf","dialog",0,"space=2");
   zdialog_add_widget(zd,"button","hostselect","hbhf","Select host image files","space=5");
   zdialog_add_widget(zd,"label","hostcount","hbhf","no files selected","space=10");

   zdialog_add_widget(zd,"hbox","hbovf","dialog",0,"space=2");
   zdialog_add_widget(zd,"button","ovselect","hbovf","Select overlay file","space=5");
   zdialog_add_widget(zd,"label","ovfile","hbovf","no file selected","space=10");

   zdialog_add_widget(zd,"hsep","hsep1","dialog",0,"space=5");

   zdialog_add_widget(zd,"hbox","hbpos1","dialog",0,"space=1");
   zdialog_add_widget(zd,"label","labpos1","hbpos1","Overlay position in host image:","space=5");
   zdialog_add_widget(zd,"hbox","hbpos2","dialog",0,"space=1");
   zdialog_add_widget(zd,"label","space","hbpos2","","space=10");
   zdialog_add_widget(zd,"label","labtop","hbpos2","% from top:","space=2");
   zdialog_add_widget(zd,"zspin","pcttop","hbpos2","1|99|1|99","space=2");
   zdialog_add_widget(zd,"label","space","hbpos2","","space=10");
   zdialog_add_widget(zd,"label","lableft","hbpos2","% from left:","space=2");
   zdialog_add_widget(zd,"zspin","pctleft","hbpos2","1|99|1|99","space=2");

   zdialog_add_widget(zd,"hsep","hsep2","dialog",0,"space=5");

   zdialog_add_widget(zd,"hbox","hbwidth1","dialog");
   zdialog_add_widget(zd,"label","labwidth1","hbwidth1","Overlay width, % host image width:","space=5");
   zdialog_add_widget(zd,"zspin","pctwidth","hbwidth1","5|95|1|20","space=2");
   zdialog_add_widget(zd,"hbox","hbwidth2","dialog");
   zdialog_add_widget(zd,"check","Fwinadj","hbwidth2","Make width constant for window size","space=6");
   zdialog_add_widget(zd,"hbox","hbwidth3","dialog");
   zdialog_add_widget(zd,"label","space","hbwidth3","","space=10");
   zdialog_add_widget(zd,"label","labwinww","hbwidth3","width","space=2");
   zdialog_add_widget(zd,"zspin","winww","hbwidth3","100|9999|1|2000","space=2");
   zdialog_add_widget(zd,"label","space","hbwidth3","","space=10");
   zdialog_add_widget(zd,"label","labwinhh","hbwidth3","height","space=2");
   zdialog_add_widget(zd,"zspin","winhh","hbwidth3","100|9999|1|1000","space=2");
   zdialog_add_widget(zd,"zbutton","refresh","hbwidth3","refresh","space=15");
   zdialog_add_ttip(zd,"refresh","set current window size");

   zdialog_add_widget(zd,"hsep","hsep3","dialog",0,"space=5");

   zdialog_add_widget(zd,"hbox","hbrepl","dialog",0,"space=1");
   zdialog_add_widget(zd,"check","Frepl","hbrepl","Replace host files","space=6");
   zdialog_add_widget(zd,"check","Fvers","hbrepl","Make new versions","space=6");

   if (SFcount) {
      snprintf(text,100,"%d image files selected",SFcount);                      //  show selected files count
      zdialog_stuff(zd,"hostcount",text);
   }

   if (ovfile) {                                                                 //  show overlay file if known
      pp = strrchr(ovfile,'/');
      zdialog_stuff(zd,"ovfile",pp+1);
   }

   pctwidth = 20;                                                                //  match dialog defaults
   pcttop = 99;
   pctleft = 99;

   Fwinadj = 0;
   gtk_window_get_size(MWIN,&winww,&winhh);
   zdialog_stuff(zd,"winww",winww);                                              //  default window = current size
   zdialog_stuff(zd,"winhh",winhh);

   Frepl = 0;
   Fvers = 1;                                                                    //  default new version
   zdialog_stuff(zd,"Frepl",Frepl);
   zdialog_stuff(zd,"Fvers",Fvers);

   if (ovfile && ! ovfilepxb)
      ovfilepxb = PXB_load(ovfile,1);

   zdialog_run(zd,batch_overlay_dialog_event,"parent");                          //  run dialog
   zstat = zdialog_wait(zd);                                                     //  wait for completion
   zdialog_free(zd);

   if (zstat != 1) {                                                             //  canceled
      Plog(0,"canceled \n");
      Fblock(0);
      return;
   }

   free_resources();                                                             //  no current file                       24.30

   zdpop = popup_report_open("Processing files",Mwin,600,300,0,0,0,"X",0);       //  log report

   Funcbusy(+1);                                                                 //  24.10

   for (ii = 0; ii < SFcount; ii++)                                              //  loop selected files
   {
      zmainloop();                                                               //  keep GTK alive

      if (outfile) zfree(outfile);
      outfile = 0;

      if (infilepxm) PXM_free(infilepxm);
      infilepxm = 0;

      if (! zdialog_valid(zdpop)) break;                                         //  report canceled

      infile = SelFiles[ii];                                                     //  input file

      if (image_file_type(infile) != IMAGE) {
         popup_report_write2(zdpop,0,"*** invalid file \n");
         continue;
      }

      popup_report_write2(zdpop,0,"\n");
      popup_report_write2(zdpop,0,"%s \n",infile);                               //  log each input file

      outfile = f_realpath(infile);                                              //  outfile = infile
      if (! outfile) {
         popup_report_write2(zdpop,0,"*** cannot get real path of input file \n");
         continue;
      }

      if (Fvers) {
         pp = file_new_version(outfile);                                         //  outfile is new version
         zfree(outfile);
         outfile = pp;
         if (! outfile) {
            popup_report_write2(zdpop,0,"*** cannot make new version of input file \n");
            continue;
         }
      }

      infilepxm = PXM_load(infile,0);                                            //  load input host file
      if (! infilepxm) {
         popup_report_write2(zdpop,0,"*** cannot load input file \n");
         continue;
      }

      ovww = 0.01 * pctwidth * infilepxm->ww + 0.5;                              //  overlay width, % host image width

      if (Fwinadj) {                                                             //  increase overlay width if left/right
         infileAR = 1.0 * infilepxm->ww / infilepxm->hh;                         //    margins needed for 'tall' image
         winAR = 1.0 * winww / winhh;
         if (winAR > infileAR) ovww = ovww * winAR / infileAR;
      }

      if (ovww < 20) ovww = 20;                                                  //  sanity limit

      ovhh = 1.0 * ovfilepxb->hh * ovww / ovfilepxb->ww + 0.5;                   //  overlay image height

      if (ovpxb) PXB_free(ovpxb);
      ovpxb = PXB_rescale(ovfilepxb,ovww,ovhh);                                  //  rescale overlay image

      ovorgx = 0.01 * pctleft * (infilepxm->ww - ovww);                          //  overlay posn from host image left edge
      ovorgy = 0.01 * pcttop * (infilepxm->hh - ovhh);                           //  overlay posn from host image top edge

      for (py1 = 0; py1 < ovhh; py1++)                                           //  loop overlay image pixels
      for (px1 = 0; px1 < ovww; px1++)
      {
         px2 = ovorgx + px1;                                                     //  corresp. host image pixel
         py2 = ovorgy + py1;

         pix1 = PXBpix(ovpxb,px1,py1);                                           //  overlay image pixel
         pix2 = PXMpix(infilepxm,px2,py2);                                       //  host image pixel

         if (ovpxb->nc == 4) f1 = pix1[3] / 256.0;                               //  use transparency if present
         else f1 = 1.0;
         f2 = 1.0 - f1;

         pix2[0] = f1 * pix1[0] + f2 * pix2[0];                                  //  copy pixel
         pix2[1] = f1 * pix1[1] + f2 * pix2[1];
         pix2[2] = f1 * pix1[2] + f2 * pix2[2];
      }

      err = PXM_save(infilepxm,outfile,f_load_bpc,90,0);
      if (err) {
         popup_report_write2(zdpop,0,"*** cannot save output file \n");
         continue;
      }

      load_filemeta(outfile);                                                    //  update image index for output file
      update_image_index(outfile);

      popup_report_write2(zdpop,0,"*** completed \n");
   }

   Funcbusy(-1);

   if (! zdialog_valid(zdpop)) {
      Plog(0,"*** report canceled \n");
      goto cleanup;
   }

   popup_report_write2(zdpop,0,"\n *** %s \n","COMPLETED");
   popup_report_bottom(zdpop);

cleanup:

   if (outfile) zfree(outfile);
   outfile = 0;

   if (infilepxm) PXM_free(infilepxm);
   infilepxm = 0;

   if (ovfilepxb) PXB_free(ovfilepxb);
   ovfilepxb = 0;

   if (ovpxb) PXB_free(ovpxb);
   ovpxb = 0;

   gallery(navi::galleryname,"init",0);                                          //  refresh file list
   gallery(0,"sort",-2);                                                         //  recall sort and position
   gallery(0,"paint",-1);                                                        //  repaint from same position

   Fblock(0);
   return;
}


//  dialog event and completion callback function

int batch_overlay_dialog_event(zdialog *zd, ch *event)
{
   using namespace batch_overlay;

   ch       countmess[80];
   ch       *pp, *ofile;

   if (zd->zstat)                                                                //  dialog completed
   {
      if (zd->zstat != 1) return 1;                                              //  canceled

      if (! SFcount) {                                                           //  selected host files count
         zmessageACK(Mwin,"no host files selected");
         zd->zstat = 0;
         return 1;
      }

      if (! ovfilepxb) {                                                         //  selected overlay file
         zmessageACK(Mwin,"no overlay file selected");
         zd->zstat = 0;
         return 1;
      }

      return 1;                                                                  //  finished
   }

   if (strmatch(event,"hostselect")) {
      zdialog_show(zd,0);                                                        //  hide parent dialog
      select_files(0,1);                                                         //  get list of files to convert          24.20
      zdialog_show(zd,1);
      snprintf(countmess,80,"%d image files selected",SFcount);                  //  update dialog
      zdialog_stuff(zd,"hostcount",countmess);
   }

   if (strmatch(event,"ovselect"))                                               //  select overlay image file
   {
      zdialog_show(zd,0);                                                        //  hide main dialog
      if (ovfile) ofile = select_files1(ovfile);
      else ofile = select_files1(saved_areas_folder);
      zdialog_show(zd,1);
      gallery(0,"paint",-1);                                                     //  repaint from same position

      if (! ofile) return 1;

      if (image_file_type(ofile) != IMAGE) {
         zmessageACK(Mwin,"not an image file");
         return 1;
      }

      if (ovfilepxb) PXB_free(ovfilepxb);                                        //  create overlay PXB pixmap
      ovfilepxb = PXB_load(ofile,1);
      if (! ovfilepxb) return 1;

      if (ovfile) zfree(ovfile);                                                 //  selected file --> dialog
      ovfile = ofile;
      pp = strrchr(ovfile,'/');
      zdialog_stuff(zd,"ovfile",pp+1);
   }

   if (strmatch(event,"pctwidth"))                                               //  overlay width % value
      zdialog_fetch(zd,"pctwidth",pctwidth);

   if (strmatch(event,"pcttop"))                                                 //  overlay position from top
      zdialog_fetch(zd,"pcttop",pcttop);

   if (strmatch(event,"pctleft"))                                                //  overlay position from left
      zdialog_fetch(zd,"pctleft",pctleft);

   if (strmatch(event,"Fwinadj"))                                                //  adjust overlay width for window
      zdialog_fetch(zd,"Fwinadj",Fwinadj);

   if (strmatch(event,"winww"))                                                  //  window width
      zdialog_fetch(zd,"winww",winww);

   if (strmatch(event,"winhh"))                                                  //  window height
      zdialog_fetch(zd,"winhh",winhh);

   if (strmatch(event,"refresh")) {                                              //  refresh current window size
      gtk_window_get_size(MWIN,&winww,&winhh);
      zdialog_stuff(zd,"winww",winww);                                           //  target window = current size
      zdialog_stuff(zd,"winhh",winhh);
   }

   if (strmatch(event,"Frepl")) {                                                //  replace host files
      zdialog_fetch(zd,"Frepl",Frepl);
      Fvers = 1 - Frepl;
      zdialog_stuff(zd,"Fvers",Fvers);
   }

   if (strmatch(event,"Fvers")) {                                                //  make new versions
      zdialog_fetch(zd,"Fvers",Fvers);
      Frepl = 1 - Fvers;
      zdialog_stuff(zd,"Frepl",Frepl);
   }

   return 1;
}


/********************************************************************************/

//  Select files and output a file containing the selected file names.

namespace imagelist_images
{
   zdialog  *zd;
   ch       outfile[300];
};


//  menu function

void m_export_filelist(GtkWidget *, ch *)
{
   using namespace imagelist_images;

   int   export_filelist_dialog_event(zdialog *zd, ch *event);

   FILE     *fid;
   int      ii, zstat;
   ch       *title = "Create a file of selected image files";
   ch       text[100];

   F1_help_topic = "export file list";

   Plog(1,"m_export_filelist \n");

   if (Findexvalid == 0) {
      zmessageACK(Mwin,"image index disabled");                                  //  no image index
      return;
   }

   if (Fblock("export file list")) return;

/***
       ____________________________________________
      |    Create a file of selected image files   |
      |                                            |
      |  [Select Files]  NNN files selected        |
      |  Output File [__________________] [Browse] |
      |                                            |
      |                              [Proceed] [X] |
      |____________________________________________|

***/

   zd = zdialog_new(title,Mwin,"Proceed"," X ",null);

   zdialog_add_widget(zd,"hbox","hbif","dialog",0,"space=3");
   zdialog_add_widget(zd,"button","infiles","hbif","Select Files","space=3");
   zdialog_add_widget(zd,"label","Nfiles","hbif","no files selected","space=10");

   zdialog_add_widget(zd,"hbox","hbof","dialog",0,"space=3");
   zdialog_add_widget(zd,"label","labof","hbof","Output File","space=3");
   zdialog_add_widget(zd,"zentry","outfile","hbof",0,"size=30|space=5");
   zdialog_add_widget(zd,"button","browse","hbof","Browse","space=5");

   snprintf(text,100,"%d image files selected",SFcount);                         //  show selected files count
   zdialog_stuff(zd,"Nfiles",text);

   if (*outfile) zdialog_stuff(zd,"outfile",outfile);

   zdialog_run(zd,export_filelist_dialog_event,"parent");                        //  run dialog, wait for response

retry:
   zstat = zdialog_wait(zd);
   if (zstat != 1) {
      zdialog_free(zd);
      Fblock(0);
      return;
   }

   free_resources();                                                             //  no current file                       24.30

   zdialog_fetch(zd,"outfile",outfile,300);                                      //  get output file from dialog

   if (! SFcount) {
      zmessageACK(Mwin,"no input files selected");
      zd->zstat = 0;
      goto retry;                                                                //  no input files
   }

   if (! *outfile) {
      zmessageACK(Mwin,"no output file selected");
      zd->zstat = 0;
      goto retry;                                                                //  no input files
   }

   fid = fopen(outfile,"w");                                                     //  open output file
   if (! fid) {
      zmessageACK(Mwin,strerror(errno));                                         //  error
      zd->zstat = 0;
      goto retry;                                                                //  no input files
   }

   zdialog_free(zd);

   for (ii = 0; ii < SFcount; ii++)                                              //  write input file names to output
      fprintf(fid,"%s\n",SelFiles[ii]);

   fclose(fid);

   zmessageACK(Mwin,"COMPLETED");
   
   Fblock(0);
   return;
}


//  dialog event and completion function

int export_filelist_dialog_event(zdialog *zd, ch *event)
{
   using namespace imagelist_images;

   ch       *file;
   ch       countmess[80];

   if (strmatch(event,"infiles"))                                                //  select image files
   {
      select_files(0,1);                                                         //  get list of files to export           24.20
      snprintf(countmess,80,"%d image files selected",SFcount);                  //  update dialog
      zdialog_stuff(zd,"Nfiles",countmess);
   }

   if (strmatch(event,"browse"))
   {
      file = zgetfile("Output File",MWIN,"save",outfile,0);
      if (file) zdialog_stuff(zd,"outfile",file);
      else zdialog_stuff(zd,"outfile","");
   }

   return 1;
}


/********************************************************************************/

//  Export selected image files to another folder with optional downsizing.
//  Only the metadata relevant for web photo services is copied.

namespace export_files_names
{
   ch       tolocation[500];
   int      Fsamesize;
   int      maxww, maxhh;
   int      Fmeta;
};


//  menu function

void m_export_files(GtkWidget*, ch *menu)
{
   using namespace export_files_names;

   int export_files_dialog_event(zdialog *zd, ch *event);

   zdialog     *zd, *zdpop;
   int         ii, cc, err, ww, hh, zstat;
   PXM         *pxmin, *pxmout;
   ch          *infile, *outfile, *pp, text[100];
   float       scale, wscale, hscale;
   #define     NK 5
   ch          *keys[NK] = { meta_date_key, meta_tags_key, meta_copyright_key,
                             meta_description_key, meta_title_key };             //  location keys removed                 24.60
   ch          *kdata[NK];

   F1_help_topic = "export files";

   Plog(1,"m_export_files \n");

   if (Findexvalid == 0) {
      zmessageACK(Mwin,"image index disabled");                                  //  no image index
      return;
   }

   if (Fblock("export files")) return;

/***
       __________________________________________________
      |                Export Files                      |
      |                                                  |
      |  [Select Files]  N files selected                |
      |  To Location [________________________] [Browse] |
      |  Max. Width [____]  Height [____]  [x] no change |
      |  [x] export metadata                             |
      |                                                  |
      |                                    [Proceed] [X] |
      |__________________________________________________|

***/

   zd = zdialog_new("Export Files",Mwin,"Proceed"," X ",null);
   zdialog_add_widget(zd,"hbox","hbf","dialog");
   zdialog_add_widget(zd,"button","files","hbf","Select Files","space=5");
   zdialog_add_widget(zd,"label","fcount","hbf","no files selected","space=10");
   zdialog_add_widget(zd,"hbox","hbloc","dialog");
   zdialog_add_widget(zd,"label","labloc","hbloc","To Location","space=5");
   zdialog_add_widget(zd,"zentry","toloc","hbloc",0,"expand");
   zdialog_add_widget(zd,"button","browse","hbloc","Browse","space=5");
   zdialog_add_widget(zd,"hbox","hbwh","dialog");
   zdialog_add_widget(zd,"label","labw","hbwh","max. Width","space=5");
   zdialog_add_widget(zd,"zentry","maxww","hbwh","1000","size=5");
   zdialog_add_widget(zd,"label","space","hbwh",0,"space=5");
   zdialog_add_widget(zd,"label","labh","hbwh","Height","space=5");
   zdialog_add_widget(zd,"zentry","maxhh","hbwh","700","size=5");
   zdialog_add_widget(zd,"check","samesize","hbwh","no change","space=12");
   zdialog_add_widget(zd,"hbox","hbmeta","dialog");
   zdialog_add_widget(zd,"check","meta","hbmeta","export metadata");

   zdialog_load_inputs(zd);                                                      //  preload prior location

   snprintf(text,100,"%d image files selected",SFcount);                         //  show selected files count
   zdialog_stuff(zd,"fcount",text);

   zdialog_resize(zd,400,0);
   zdialog_run(zd,export_files_dialog_event,"parent");                           //  run dialog
   zstat = zdialog_wait(zd);                                                     //  wait for completion
   zdialog_free(zd);

   if (zstat != 1) {
      Fblock(0);
      return;
   }

   free_resources();                                                             //  no current file                       24.30

   Funcbusy(+1);

   zdpop = popup_report_open("exporting files",Mwin,600,400,0,0,0,"X",0);        //  log report

   Funcbusy(+1);                                                                 //  24.10

   for (ii = 0; ii < SFcount; ii++)                                              //  loop selected files
   {
      zmainloop();                                                               //  keep GTK awake

      if (! zdialog_valid(zdpop)) break;                                         //  canceled

      infile = SelFiles[ii];                                                     //  input filespec
      popup_report_write2(zdpop,0,"%s \n",infile);

      pp = strrchr(infile,'/');                                                  //  construct output filespec
      if (! pp) continue;
      cc = strlen(pp) + 8;
      outfile = zstrdup(tolocation,"export files",cc);
      strcat(outfile,pp);
      pp = strrchr(outfile,'.');                                                 //  outfile is type .jpg
      if (! pp) continue;
      strcpy(pp,".jpg");

      pxmin = PXM_load(infile,0);                                                //  read input file
      if (! pxmin) {
         popup_report_write2(zdpop,1," *** file type not supported \n");
         zfree(outfile);
         continue;
      }

      ww = pxmin->ww;                                                            //  input file size
      hh = pxmin->hh;

      if (Fsamesize) pxmout = pxmin;                                             //  same size, output = input
      else {
         wscale = hscale = 1.0;
         if (ww > maxww) wscale = 1.0 * maxww / ww;                              //  compute new size
         if (hh > maxhh) hscale = 1.0 * maxhh / hh;
         if (wscale < hscale) scale = wscale;
         else scale = hscale;
         if (scale > 0.999) pxmout = pxmin;                                      //  no change
         else {
            ww = ww * scale;
            hh = hh * scale;
            pxmout = PXM_rescale(pxmin,ww,hh);                                   //  rescaled output file
            PXM_free(pxmin);                                                     //  free memory
         }
      }

      err = PXM_JPG_save(pxmout,outfile,jpeg_def_quality);                       //  write output file
      if (err) popup_report_write2(zdpop,1," *** cannot create new file \n");

      if (! err && Fmeta) {                                                      //  optional copy metadata
         err = meta_get1(infile,(ch **) keys,kdata,NK);
         if (! err) {
            err = meta_put(outfile,(ch **) keys,kdata,NK);
            if (err) popup_report_write2(zdpop,1," *** metadata update errpr \n");
         }
      }

      PXM_free(pxmout);
      zfree(outfile);
   }

   Funcbusy(-1);

   if (! zdialog_valid(zdpop)) {
      Plog(0,"*** report canceled \n");
      goto cleanup;
   }

   popup_report_write2(zdpop,0,"\n *** COMPLETED \n");
   popup_report_bottom(zdpop);

cleanup:
   Funcbusy(-1);
   Fblock(0);
   return;
}


//  dialog event and completion callback function

int export_files_dialog_event(zdialog *zd, ch *event)
{
   using namespace export_files_names;

   int      cc;
   ch       countmess[80];
   ch       *ploc;

   if (strmatch(event,"files"))                                                  //  select files to export
   {
      select_files(0,1);                                                         //  get list of files to export           24.20
      snprintf(countmess,80,"%d image files selected",SFcount);                  //  update dialog
      zdialog_stuff(zd,"fcount",countmess);
   }

   if (strmatch(event,"browse")) {
      zdialog_fetch(zd,"toloc",tolocation,500);
      ploc = zgetfile("Select folder",MWIN,"folder",tolocation);                 //  new location browse
      if (! ploc) return 1;
      zdialog_stuff(zd,"toloc",ploc);
      zfree(ploc);
   }

   if (! zd->zstat) return 1;                                                    //  wait for dialog completion
   if (zd->zstat != 1) return 1;                                                 //  canceled

   if (! SFcount) {                                                              //  [proceed]
      zmessageACK(Mwin,"no files selected");                                     //  no files selected
      zd->zstat = 0;                                                             //  keep dialog active
      return 1;
   }

   zdialog_fetch(zd,"toloc",tolocation,500);                                     //  get output location
   if (! dirfile(tolocation)) {
      zmessageACK(Mwin,"location is not a folder");
      zd->zstat = 0;
   }

   cc = strlen(tolocation) - 1;                                                  //  remove trailing '/' if present
   if (tolocation[cc] == '/') tolocation[cc] = 0;

   zdialog_fetch(zd,"samesize",Fsamesize);                                       //  get rescale options
   zdialog_fetch(zd,"maxww",maxww);
   zdialog_fetch(zd,"maxhh",maxhh);
   zdialog_fetch(zd,"meta",Fmeta);                                               //  metadata option

   return 1;
}