OSDN Git Service

b19d009bc5a9e2863d600c35d306060a8ad55abe
[handbrake-jp/handbrake-jp-git.git] / gtk / src / preset_xlat.c
1 #include <stdio.h>
2 #include <string.h>
3 #include <glib.h>
4 #include <glib/gstdio.h>
5 #include "plist.h"
6 #include "values.h"
7
8 static GValue *defaults;
9
10 typedef struct
11 {
12         gchar *mac_val;
13         gchar *lin_val;
14 } value_map_t;
15
16 static value_map_t vcodec_xlat[] =
17 {
18         {"MPEG-4 (FFmpeg)", "ffmpeg"},
19         {"MPEG-4 (XviD)", "xvid"},
20         {"H.264 (x264)", "x264"},
21         {"VP3 (Theora)", "theora"},
22         {NULL,NULL}
23 };
24
25 static value_map_t acodec_xlat[] =
26 {
27         {"AAC (faac)", "faac"},
28         {"AC3 Passthru", "ac3"},
29         {"MP3 (lame)", "lame"},
30         {"Vorbis (vorbis)", "vorbis"},
31         {NULL,NULL}
32 };
33
34 static value_map_t subtitle_xlat[] =
35
36         { "None", "none" },
37         { "Auto", "auto" },
38         { "Any", "und" },
39         { "Afar", "aar" },
40         { "Abkhazian", "abk" },
41         { "Afrikaans", "afr" },
42         { "Akan", "aka" },
43         { "Albanian", "sqi" },
44         { "Amharic", "amh" },
45         { "Arabic", "ara" },
46         { "Aragonese", "arg" },
47         { "Armenian", "hye" },
48         { "Assamese", "asm" },
49         { "Avaric", "ava" },
50         { "Avestan", "ave" },
51         { "Aymara", "aym" },
52         { "Azerbaijani", "aze" },
53         { "Bashkir", "bak" },
54         { "Bambara", "bam" },
55         { "Basque", "eus" },
56         { "Belarusian", "bel" },
57         { "Bengali", "ben" },
58         { "Bihari", "bih" },
59         { "Bislama", "bis" },
60         { "Bosnian", "bos" },
61         { "Breton", "bre" },
62         { "Bulgarian", "bul" },
63         { "Burmese", "mya" },
64         { "Catalan", "cat" },
65         { "Chamorro", "cha" },
66         { "Chechen", "che" },
67         { "Chinese", "zho" },
68         { "Church Slavic", "chu" },
69         { "Chuvash", "chv" },
70         { "Cornish", "cor" },
71         { "Corsican", "cos" },
72         { "Cree", "cre" },
73         { "Czech", "ces" },
74         { "Danish", "dan" },
75         { "Divehi", "div" },
76         { "Dutch", "nld" },
77         { "Dzongkha", "dzo" },
78         { "English", "eng" },
79         { "Esperanto", "epo" },
80         { "Estonian", "est" },
81         { "Ewe", "ewe" },
82         { "Faroese", "fao" },
83         { "Fijian", "fij" },
84         { "Finnish", "fin" },
85         { "French", "fra" },
86         { "Western Frisian", "fry" },
87         { "Fulah", "ful" },
88         { "Georgian", "kat" },
89         { "German", "deu" },
90         { "Gaelic (Scots)", "gla" },
91         { "Irish", "gle" },
92         { "Galician", "glg" },
93         { "Manx", "glv" },
94         { "Greek, Modern", "ell" },
95         { "Guarani", "grn" },
96         { "Gujarati", "guj" },
97         { "Haitian", "hat" },
98         { "Hausa", "hau" },
99         { "Hebrew", "heb" },
100         { "Herero", "her" },
101         { "Hindi", "hin" },
102         { "Hiri Motu", "hmo" },
103         { "Hungarian", "hun" },
104         { "Igbo", "ibo" },
105         { "Icelandic", "isl" },
106         { "Ido", "ido" },
107         { "Sichuan Yi", "iii" },
108         { "Inuktitut", "iku" },
109         { "Interlingue", "ile" },
110         { "Interlingua", "ina" },
111         { "Indonesian", "ind" },
112         { "Inupiaq", "ipk" },
113         { "Italian", "ita" },
114         { "Javanese", "jav" },
115         { "Japanese", "jpn" },
116         { "Kalaallisut", "kal" },
117         { "Kannada", "kan" },
118         { "Kashmiri", "kas" },
119         { "Kanuri", "kau" },
120         { "Kazakh", "kaz" },
121         { "Central Khmer", "khm" },
122         { "Kikuyu", "kik" },
123         { "Kinyarwanda", "kin" },
124         { "Kirghiz", "kir" },
125         { "Komi", "kom" },
126         { "Kongo", "kon" },
127         { "Korean", "kor" },
128         { "Kuanyama", "kua" },
129         { "Kurdish", "kur" },
130         { "Lao", "lao" },
131         { "Latin", "lat" },
132         { "Latvian", "lav" },
133         { "Limburgan", "lim" },
134         { "Lingala", "lin" },
135         { "Lithuanian", "lit" },
136         { "Luxembourgish", "ltz" },
137         { "Luba-Katanga", "lub" },
138         { "Ganda", "lug" },
139         { "Macedonian", "mkd" },
140         { "Marshallese", "mah" },
141         { "Malayalam", "mal" },
142         { "Maori", "mri" },
143         { "Marathi", "mar" },
144         { "Malay", "msa" },
145         { "Malagasy", "mlg" },
146         { "Maltese", "mlt" },
147         { "Moldavian", "mol" },
148         { "Mongolian", "mon" },
149         { "Nauru", "nau" },
150         { "Navajo", "nav" },
151         { "Ndebele, South", "nbl" },
152         { "Ndebele, North", "nde" },
153         { "Ndonga", "ndo" },
154         { "Nepali", "nep" },
155         { "Norwegian Nynorsk", "nno" },
156         { "Norwegian Bokmål", "nob" },
157         { "Norwegian", "nor" },
158         { "Chichewa; Nyanja", "nya" },
159         { "Occitan", "oci" },
160         { "Ojibwa", "oji" },
161         { "Oriya", "ori" },
162         { "Oromo", "orm" },
163         { "Ossetian", "oss" },
164         { "Panjabi", "pan" },
165         { "Persian", "fas" },
166         { "Pali", "pli" },
167         { "Polish", "pol" },
168         { "Portuguese", "por" },
169         { "Pushto", "pus" },
170         { "Quechua", "que" },
171         { "Romansh", "roh" },
172         { "Romanian", "ron" },
173         { "Rundi", "run" },
174         { "Russian", "rus" },
175         { "Sango", "sag" },
176         { "Sanskrit", "san" },
177         { "Serbian", "srp" },
178         { "Croatian", "hrv" },
179         { "Sinhala", "sin" },
180         { "Slovak", "slk" },
181         { "Slovenian", "slv" },
182         { "Northern Sami", "sme" },
183         { "Samoan", "smo" },
184         { "Shona", "sna" },
185         { "Sindhi", "snd" },
186         { "Somali", "som" },
187         { "Sotho, Southern", "sot" },
188         { "Spanish", "spa" },
189         { "Sardinian", "srd" },
190         { "Swati", "ssw" },
191         { "Sundanese", "sun" },
192         { "Swahili", "swa" },
193         { "Swedish", "swe" },
194         { "Tahitian", "tah" },
195         { "Tamil", "tam" },
196         { "Tatar", "tat" },
197         { "Telugu", "tel" },
198         { "Tajik", "tgk" },
199         { "Tagalog", "tgl" },
200         { "Thai", "tha" },
201         { "Tibetan", "bod" },
202         { "Tigrinya", "tir" },
203         { "Tonga", "ton" },
204         { "Tswana", "tsn" },
205         { "Tsonga", "tso" },
206         { "Turkmen", "tuk" },
207         { "Turkish", "tur" },
208         { "Twi", "twi" },
209         { "Uighur", "uig" },
210         { "Ukrainian", "ukr" },
211         { "Urdu", "urd" },
212         { "Uzbek", "uzb" },
213         { "Venda", "ven" },
214         { "Vietnamese", "vie" },
215         { "Volapük", "vol" },
216         { "Welsh", "cym" },
217         { "Walloon", "wln" },
218         { "Wolof", "wol" },
219         { "Xhosa", "xho" },
220         { "Yiddish", "yid" },
221         { "Yoruba", "yor" },
222         { "Zhuang", "zha" },
223         { "Zulu", "zul" },
224         {NULL, NULL}
225 };
226
227 value_map_t container_xlat[] =
228 {
229         {"MP4 file", "mp4"},
230         {"M4V file", "m4v"},
231         {"MKV file", "mkv"},
232         {"AVI file", "avi"},
233         {"OGM file", "ogm"},
234         {NULL, NULL}
235 };
236
237 value_map_t framerate_xlat[] =
238 {
239         {"Same as source", "source"},
240         {"5", "5"},
241         {"10", "10"},
242         {"12", "12"},
243         {"15", "15"},
244         {"23.976", "23.976"},
245         {"24", "24"},
246         {"25", "25"},
247         {"29.97", "29.97"},
248         {NULL, NULL}
249 };
250
251 value_map_t samplerate_xlat[] =
252 {
253         {"Auto", "source"},
254         {"22.05", "22.05"},
255         {"24", "24"},
256         {"32", "32"},
257         {"44.1", "44.1"},
258         {"48", "48"},
259         {NULL, NULL}
260 };
261
262 value_map_t mix_xlat[] =
263 {
264         {"Mono", "mono"},
265         {"Stereo", "stereo"},
266         {"Dolby Surround", "dpl1"},
267         {"Dolby Pro Logic II", "dpl2"},
268         {"6-channel discrete", "6ch"},
269         {"AC3 Passthru", "none"},
270         {NULL, NULL}
271 };
272
273 value_map_t deint_xlat[] =
274 {
275         {"0", "none"},
276         {"1", "fast"},
277         {"2", "slow"},
278         {"3", "slower"},
279         {NULL, NULL}
280 };
281
282 value_map_t denoise_xlat[] =
283 {
284         {"0", "none"},
285         {"1", "weak"},
286         {"2", "medium"},
287         {"3", "strong"},
288         {NULL, NULL}
289 };
290
291 typedef struct
292 {
293         gchar *mac_key;
294         gchar *lin_key;
295         value_map_t *value_map;
296         gboolean ignore;
297 } key_map_t;
298
299 key_map_t key_map[] = 
300 {
301         {"Audio1Bitrate", NULL, NULL, FALSE},
302         {"Audio1Encoder", NULL, NULL, FALSE},
303         {"Audio1Mixdown", NULL, NULL, FALSE},
304         {"Audio1Samplerate", NULL, NULL, FALSE},
305         {"Audio1Track", NULL, NULL, FALSE},
306         {"Audio1TrackDescription", NULL, NULL, FALSE},
307         {"Audio1TrackDRCSlider", NULL, NULL, FALSE},
308         {"Audio2Bitrate", NULL, NULL, FALSE},
309         {"Audio2Encoder", NULL, NULL, FALSE},
310         {"Audio2Mixdown", NULL, NULL, FALSE},
311         {"Audio2Samplerate", NULL, NULL, FALSE},
312         {"Audio2Track", NULL, NULL, FALSE},
313         {"Audio2TrackDescription", NULL, NULL, FALSE},
314         {"Audio2TrackDRCSlider", NULL, NULL, FALSE},
315         {"ChapterMarkers", "chapter_markers", NULL, FALSE},
316         {"Default", "Default", NULL, FALSE},
317         {"FileFormat", "container", container_xlat, FALSE},
318         {"Folder", NULL, NULL, TRUE},
319         {"Mp4HttpOptimize", "http_optimize_mp4", NULL, FALSE},
320         {"Mp4iPodCompatible", "ipod_file", NULL, FALSE},
321         {"Mp4LargeFile", "large_mp4", NULL, FALSE},
322         {"PictureAutoCrop", "autocrop", NULL, FALSE},
323         {"PictureBottomCrop", NULL, NULL, TRUE},
324         {"PictureDeblock", "deblock", NULL, FALSE},
325         {"PictureDecomb", "decomb", NULL, FALSE},
326         {"PictureDeinterlace", "deinterlace", deint_xlat, FALSE},
327         {"PictureDenoise", "denoise", denoise_xlat, FALSE},
328         {"PictureDetelecine", "detelecine", NULL, FALSE},
329         {"PictureHeight", "max_height", NULL, FALSE},
330         {"PictureKeepRatio", "keep_aspect", NULL, FALSE},
331         {"PictureLeftCrop", NULL, NULL, TRUE},
332         {"PicturePAR", NULL, NULL, FALSE},
333         {"PictureRightCrop", NULL, NULL, TRUE},
334         {"PictureTopCrop", NULL, NULL, TRUE},
335         {"PictureWidth", "max_width", NULL, FALSE},
336         {"PresetDescription", "preset_description", NULL, FALSE},
337         {"PresetName", "preset_name", NULL, FALSE},
338         {"Subtitles", "subtitle_lang", subtitle_xlat, FALSE},
339         {"SubtitlesForced", "forced_subtitles", NULL, FALSE},
340         {"Type", NULL, NULL, TRUE},
341         {"UsesMaxPictureSettings", NULL, NULL, FALSE},
342         {"UsesPictureFilters", NULL, NULL, TRUE},
343         {"UsesPictureSettings", NULL, NULL, FALSE},
344         {"VFR", NULL, NULL, TRUE},
345         {"VideoAvgBitrate", "video_bitrate", NULL, FALSE},
346         {"VideoEncoder", "video_codec", vcodec_xlat, FALSE},
347         {"VideoFramerate", "framerate", framerate_xlat, FALSE},
348         {"VideoGrayScale", "grayscale", NULL, FALSE},
349         {"VideoQualitySlider", NULL, NULL, FALSE},
350         {"VideoQualityType", NULL, NULL, FALSE},
351         {"VideoTargetSize", "video_target_size", NULL, FALSE},
352         {"VideoTwoPass", "two_pass", NULL, FALSE},
353         {"VideoTurboTwoPass", "turbo", NULL, FALSE},
354         {"x264Option", "x264_options", NULL, FALSE},
355         {NULL, NULL}
356 };
357
358 const gint
359 key_xlat(key_map_t *key_map, const gchar *mac_key)
360 {
361         gint ii;
362
363         for (ii = 0; key_map[ii].mac_key; ii++)
364         {
365                 if (strcmp(mac_key, key_map[ii].mac_key) == 0)
366                 {
367                         if (key_map[ii].ignore)
368                                 return -1;
369                         return ii;
370                 }
371         }
372         g_warning("Unrecognized key: (%s)", mac_key);
373         return -1;
374 }
375
376 static GValue*
377 value_xlat(
378         GValue *defaults, 
379         key_map_t *key_map, 
380         gint key_index, 
381         GValue *mac_val)
382 {
383         GValue *gval, *def_val;
384         const gchar *lin_key = key_map[key_index].lin_key;
385         value_map_t *value_map = key_map[key_index].value_map;
386
387         def_val = ghb_dict_lookup(defaults, lin_key);
388         if (def_val)
389         {
390                 if (value_map)
391                 {
392                         gint ii;
393                         gchar *str;
394                         GValue *sval;
395
396                         str = ghb_value_string(mac_val);
397                         for (ii = 0; value_map[ii].mac_val; ii++)
398                         {
399                                 if (strcmp(str, value_map[ii].mac_val) == 0)
400                                 {
401                                         sval = ghb_string_value_new(value_map[ii].lin_val);
402                                         g_free(str);
403                                         gval = ghb_value_new(G_VALUE_TYPE(def_val));
404                                         if (!g_value_transform(sval, gval))
405                                         {
406                                                 g_warning("1 can't transform");
407                                                 ghb_value_free(gval);
408                                                 ghb_value_free(sval);
409                                                 return NULL;
410                                         }
411                                         ghb_value_free(sval);
412                                         return gval;
413                                 }
414                         }
415                         g_warning("Can't map value: (%s)", str);
416                         g_free(str);
417                 }
418                 else
419                 {
420                         gval = ghb_value_new(G_VALUE_TYPE(def_val));
421                         if (!g_value_transform(mac_val, gval))
422                         {
423                                 g_warning("2 can't transform");
424                                 ghb_value_free(gval);
425                                 return NULL;
426                         }
427                         return gval;
428                 }
429         }
430         else
431         {
432                 g_warning("Bad key: (%s)", lin_key);
433                 return NULL;
434         }
435         return NULL;
436 }
437
438 key_map_t audio_key_map[] =
439 {
440         {"Audio1Bitrate", "audio_bitrate", NULL, FALSE},
441         {"Audio1Encoder", "audio_codec", acodec_xlat, FALSE},
442         {"Audio1Mixdown", "audio_mix", mix_xlat, FALSE},
443         {"Audio1Samplerate", "audio_rate", samplerate_xlat, FALSE},
444         {"Audio1Track", NULL, NULL, TRUE},
445         {"Audio1TrackDescription", NULL, NULL, TRUE},
446         {"Audio1TrackDRCSlider", "audio_drc", NULL, FALSE},
447         {"Audio2Bitrate", "audio_bitrate", NULL, FALSE},
448         {"Audio2Encoder", "audio_codec", acodec_xlat, FALSE},
449         {"Audio2Mixdown", "audio_mix", mix_xlat, FALSE},
450         {"Audio2Samplerate", "audio_rate", samplerate_xlat, FALSE},
451         {"Audio2Track", NULL, NULL, TRUE},
452         {"Audio2TrackDescription", NULL, NULL, TRUE},
453         {"Audio2TrackDRCSlider", "audio_drc", NULL, FALSE},
454         {NULL, NULL}
455 };
456
457 static void
458 hard_value_xlat(GValue *lin_dict, const gchar *mac_key, GValue *mac_val)
459 {
460         if (strcmp(mac_key, "VideoQualitySlider") == 0)
461         {
462                 gint vquality;
463
464                 vquality = (ghb_value_double(mac_val) + 0.005) * 100.0;
465                 ghb_dict_insert(lin_dict, "video_quality", 
466                                                         ghb_int_value_new(vquality));
467         }
468         else if (strcmp(mac_key, "UsesMaxPictureSettings") == 0)
469         {
470                 GValue *gval;
471
472                 gval = ghb_dict_lookup(lin_dict, "autoscale");
473                 if (gval == NULL && ghb_value_boolean(mac_val))
474                 {
475                         ghb_dict_insert(lin_dict, "autoscale", ghb_boolean_value_new(TRUE));
476                 }
477         }
478         else if (strcmp(mac_key, "UsesPictureSettings") == 0)
479         {
480                 GValue *gval;
481
482                 gval = ghb_dict_lookup(lin_dict, "autoscale");
483                 if (gval == NULL && ghb_value_int(mac_val) == 2)
484                 {
485                         ghb_dict_insert(lin_dict, "autoscale", ghb_boolean_value_new(TRUE));
486                 }
487         }
488         else if (strcmp(mac_key, "PicturePAR") == 0)
489         {
490                 gint ana;
491
492                 ana = ghb_value_int(mac_val);
493                 switch (ana)
494                 {
495                 case 0:
496                 {
497                         ghb_dict_insert(lin_dict, "anamorphic", 
498                                                         ghb_boolean_value_new(FALSE));
499                         ghb_dict_insert(lin_dict, "round_dimensions", 
500                                                         ghb_boolean_value_new(TRUE));
501                 } break;
502                 case 1:
503                 {
504                         ghb_dict_insert(lin_dict, "anamorphic", 
505                                                         ghb_boolean_value_new(TRUE));
506                         ghb_dict_insert(lin_dict, "round_dimensions", 
507                                                         ghb_boolean_value_new(FALSE));
508                 } break;
509                 case 2:
510                 {
511                         ghb_dict_insert(lin_dict, "anamorphic", 
512                                                         ghb_boolean_value_new(TRUE));
513                         ghb_dict_insert(lin_dict, "round_dimensions", 
514                                                         ghb_boolean_value_new(TRUE));
515                 } break;
516                 default:
517                 {
518                         ghb_dict_insert(lin_dict, "anamorphic", 
519                                                         ghb_boolean_value_new(TRUE));
520                         ghb_dict_insert(lin_dict, "round_dimensions", 
521                                                         ghb_boolean_value_new(TRUE));
522                 } break;
523                 }
524         }
525         else if (strcmp(mac_key, "VideoQualityType") == 0)
526         {
527                 // VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
528                 gint vqtype;
529
530                 vqtype = ghb_value_int(mac_val);
531                 switch (vqtype)
532                 {
533                 case 0:
534                 {
535                         ghb_dict_insert(lin_dict, "vquality_type_target", 
536                                                         ghb_boolean_value_new(TRUE));
537                         ghb_dict_insert(lin_dict, "vquality_type_bitrate", 
538                                                         ghb_boolean_value_new(FALSE));
539                         ghb_dict_insert(lin_dict, "vquality_type_constant", 
540                                                         ghb_boolean_value_new(FALSE));
541                 } break;
542                 case 1:
543                 {
544                         ghb_dict_insert(lin_dict, "vquality_type_target", 
545                                                         ghb_boolean_value_new(FALSE));
546                         ghb_dict_insert(lin_dict, "vquality_type_bitrate", 
547                                                         ghb_boolean_value_new(TRUE));
548                         ghb_dict_insert(lin_dict, "vquality_type_constant", 
549                                                         ghb_boolean_value_new(FALSE));
550                 } break;
551                 case 2:
552                 {
553                         ghb_dict_insert(lin_dict, "vquality_type_target", 
554                                                         ghb_boolean_value_new(FALSE));
555                         ghb_dict_insert(lin_dict, "vquality_type_bitrate", 
556                                                         ghb_boolean_value_new(FALSE));
557                         ghb_dict_insert(lin_dict, "vquality_type_constant", 
558                                                         ghb_boolean_value_new(TRUE));
559                 } break;
560                 default:
561                 {
562                         ghb_dict_insert(lin_dict, "vquality_type_target", 
563                                                         ghb_boolean_value_new(FALSE));
564                         ghb_dict_insert(lin_dict, "vquality_type_bitrate", 
565                                                         ghb_boolean_value_new(FALSE));
566                         ghb_dict_insert(lin_dict, "vquality_type_constant", 
567                                                         ghb_boolean_value_new(TRUE));
568                 } break;
569                 }
570         }
571         else
572         {
573                 gint key_index;
574                 GValue *audio_defaults;
575
576                 audio_defaults = ghb_array_get_nth(
577                         ghb_dict_lookup(defaults, "pref_audio_list"), 0);
578                 key_index = key_xlat(audio_key_map, mac_key);
579                 if (key_index >= 0)
580                 {
581                         gint audio_index, count, ii;
582                         GValue *alist, *adict, *val;
583
584                         audio_index = mac_key[5] - '1';
585                         alist = ghb_dict_lookup(lin_dict, "pref_audio_list");
586                         if (alist == NULL)
587                         {
588                                 alist = ghb_array_value_new(8);
589                                 ghb_dict_insert(lin_dict, "pref_audio_list", alist);
590                         }
591                         count = ghb_array_len(alist);
592                         for (ii = count; ii <= audio_index; ii++)
593                         {
594                                 adict = ghb_value_dup(audio_defaults);
595                                 ghb_array_append(alist, adict);
596                         }
597                         adict = ghb_array_get_nth(alist, audio_index);
598                         val = value_xlat(audio_defaults, audio_key_map, key_index, mac_val);
599                         if (val)
600                         {
601                                 ghb_dict_insert(adict, 
602                                                         g_strdup(audio_key_map[key_index].lin_key), val);
603                         }
604                 }
605         }
606 }
607
608 static void
609 parse_preset_dict(GValue *mac_dict, GValue *lin_dict)
610 {
611     GHashTableIter iter;
612     gchar *key;
613     GValue *mac_val, *val;
614
615     ghb_dict_iter_init(&iter, mac_dict);
616     // middle (void*) cast prevents gcc warning "defreferencing type-punned
617     // pointer will break strict-aliasing rules"
618         while (g_hash_table_iter_next(
619                         &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&mac_val))
620         {
621                 gint key_index;
622
623                 key_index = key_xlat(key_map, key);
624                 if (key_index >= 0)
625                 { // The simple translations
626                         if (key_map[key_index].lin_key)
627                         {
628                                 val = value_xlat(defaults, key_map, key_index, mac_val);
629                                 if (val)
630                                 {
631                                         ghb_dict_insert(lin_dict, 
632                                                                 g_strdup(key_map[key_index].lin_key), val);
633                                 }
634                         }
635                         else
636                         {
637                                 hard_value_xlat(lin_dict, key, mac_val);
638                         }
639                 }
640         }
641 }
642
643 static void
644 parse_preset_array(GValue *mac_array, GValue *lin_array)
645 {
646         gint count, ii;
647         GValue *mac_dict, *lin_dict, *gval;
648
649         count = ghb_array_len(mac_array);
650         for (ii = 0; ii < count; ii++)
651         {
652                 mac_dict = ghb_array_get_nth(mac_array, ii);
653                 
654                 // Only process builtin types
655                 if (ghb_value_int(ghb_dict_lookup(mac_dict, "Type")) != 0)
656                         continue;
657
658                 lin_dict = ghb_dict_value_new();
659                 ghb_array_append(lin_array, lin_dict);
660                 gval = ghb_dict_lookup(mac_dict, "PresetName");
661                 if (gval)
662                 {
663                         ghb_dict_insert(lin_dict, g_strdup("preset_name"), 
664                                                         ghb_value_dup(gval));
665                 }
666                 gval = ghb_dict_lookup(mac_dict, "PresetDescription");
667                 if (gval)
668                 {
669                         ghb_dict_insert(lin_dict, g_strdup("preset_description"), 
670                                                         ghb_value_dup(gval));
671                 }
672                 gval = ghb_dict_lookup(mac_dict, "Folder");
673                 if (gval && ghb_value_boolean(gval))
674                 { // Folder
675                         GValue *mval, *lval;
676
677                         mval = ghb_dict_lookup(mac_dict, "ChildrenArray");
678                         lval = ghb_array_value_new(32);
679                         ghb_dict_insert(lin_dict, g_strdup("preset_folder"), lval);
680                         ghb_dict_insert(lin_dict, g_strdup("preset_type"), 
681                                                         ghb_int_value_new(2));
682                         parse_preset_array(mval, lval);
683                 }
684                 else
685                 { // Normal preset
686                         ghb_dict_insert(lin_dict, g_strdup("preset_type"), 
687                                                         ghb_int_value_new(0));
688                         parse_preset_dict(mac_dict, lin_dict);
689                 }
690         }
691 }
692
693 static void
694 xlat(GValue *mac, GValue *lin)
695 {
696         return parse_preset_array(mac, lin);
697 }
698
699 gint
700 main(gint argc, gchar *argv[])
701 {
702         GValue *mac_plist, *lin_plist;
703         GValue *internal;
704
705         if (argc < 3)
706         {
707                 fprintf(stderr, "Usage: <mac plist> <lin plist>\n");
708                 return 1;
709         }
710         g_type_init();
711
712         ghb_register_transforms();
713         internal = ghb_plist_parse_file("internal_defaults.xml");
714         defaults = ghb_dict_lookup(internal, "Presets");
715         mac_plist = ghb_plist_parse_file(argv[1]);
716         lin_plist = ghb_array_value_new(32);
717         xlat(mac_plist, lin_plist);
718         ghb_plist_write_file(argv[2], lin_plist);
719         return 0;
720 }
721