/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
* presets.c
- * Copyright (C) John Stebbins 2008 <stebbins@stebbins>
+ * Copyright (C) John Stebbins 2008-2011 <stebbins@stebbins>
*
* presets.c is free software.
*
* any later version.
*
*/
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
#include <glib.h>
#include <glib-object.h>
#include <glib/gstdio.h>
}
}
+static void
+presets_customize(GValue *presets)
+{
+ gint count, ii;
+
+ count = ghb_array_len(presets);
+ for (ii = 0; ii < count; ii++)
+ {
+ GValue *dict;
+ gboolean folder;
+ gint ptype;
+
+ dict = ghb_array_get_nth(presets, ii);
+
+ ptype = ghb_value_int(preset_dict_get_value(dict, "Type"));
+ if (ptype != PRESETS_CUSTOM)
+ {
+ ghb_dict_insert(dict, g_strdup("Type"),
+ ghb_int64_value_new(PRESETS_CUSTOM));
+ }
+ folder = ghb_value_boolean(preset_dict_get_value(dict, "Folder"));
+ if (folder)
+ {
+ GValue *nested;
+
+ nested = ghb_dict_lookup(dict, "ChildrenArray");
+ presets_customize(nested);
+ }
+ }
+}
+
static gint*
presets_find_default2(GValue *presets, gint *len)
{
init_settings_from_dict(ud->settings, hidden, dict);
init_ui_from_dict(ud, internal, dict);
init_ui_from_dict(ud, hidden, dict);
+
+ if (dict != NULL)
+ {
+ GValue *val;
+ gboolean dd;
+
+ val = ghb_dict_lookup(dict, "PictureDecombDeinterlace");
+ if (val != NULL)
+ {
+ dd = ghb_value_boolean(val);
+ ghb_ui_update(ud, "PictureDeinterlaceDecomb", ghb_boolean_value(!dd));
+ }
+ val = ghb_dict_lookup(dict, "PictureHeight");
+ if (val != NULL)
+ {
+ ghb_ui_update(ud, "scale_height", val);
+ }
+ val = ghb_dict_lookup(dict, "PictureWidth");
+ if (val != NULL)
+ {
+ ghb_ui_update(ud, "scale_width", val);
+ }
+ }
}
void
return plist;
}
+gboolean
+ghb_lock_file(const gchar *name)
+{
+#if !defined(_WIN32)
+ gchar *config, *path;
+ int fd, lock = 0;
+
+ config = ghb_get_user_config_dir(NULL);
+ path = g_strdup_printf ("%s/%s", config, name);
+ fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
+ if (fd >= 0)
+ lock = lockf(fd, F_TLOCK, 0);
+ if (lock)
+ close(fd);
+ g_free(config);
+ g_free(path);
+ return !lock;
+#else
+ return 1;
+#endif
+}
+
+void
+ghb_write_pid_file()
+{
+#if !defined(_WIN32)
+ gchar *config, *path;
+ pid_t pid;
+ FILE *fp;
+ int fd, lock;
+
+ pid = getpid();
+
+ config = ghb_get_user_config_dir(NULL);
+ path = g_strdup_printf ("%s/ghb.pid.%d", config, pid);
+
+ fp = g_fopen(path, "w");
+ fprintf(fp, "%d\n", pid);
+ fclose(fp);
+
+ fd = open(path, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR);
+ lock = lockf(fd, F_TLOCK, 0);
+
+ g_free(config);
+ g_free(path);
+#endif
+}
+
+void
+ghb_unlink_pid_file(int pid)
+{
+ gchar *config, *path;
+
+ config = ghb_get_user_config_dir(NULL);
+ path = g_strdup_printf ("%s/ghb.pid.%d", config, pid);
+
+ if (g_file_test(path, G_FILE_TEST_IS_REGULAR))
+ {
+ g_unlink(path);
+ }
+
+ g_free(config);
+ g_free(path);
+}
+
+int
+ghb_find_pid_file()
+{
+ const gchar *file;
+ gchar *config;
+
+ config = ghb_get_user_config_dir(NULL);
+
+ if (g_file_test(config, G_FILE_TEST_IS_DIR))
+ {
+ GDir *gdir = g_dir_open(config, 0, NULL);
+ file = g_dir_read_name(gdir);
+ while (file)
+ {
+ if (strncmp(file, "ghb.pid.", 8) == 0)
+ {
+ gchar *path;
+ pid_t my_pid;
+ int pid;
+
+ sscanf(file, "ghb.pid.%d", &pid);
+ my_pid = getpid();
+ if (my_pid == pid)
+ {
+ file = g_dir_read_name(gdir);
+ continue;
+ }
+ path = g_strdup_printf("%s/%s", config, file);
+
+#if !defined(_WIN32)
+ int fd, lock = 1;
+
+ fd = open(path, O_RDWR);
+ if (fd >= 0)
+ {
+ lock = lockf(fd, F_TLOCK, 0);
+ }
+ if (lock == 0)
+ {
+ close(fd);
+ g_dir_close(gdir);
+ g_unlink(path);
+ g_free(path);
+ g_free(config);
+ return pid;
+ }
+ g_free(path);
+ close(fd);
+#else
+ g_dir_close(gdir);
+ g_unlink(path);
+ g_free(path);
+ g_free(config);
+ return pid;
+#endif
+ }
+ file = g_dir_read_name(gdir);
+ }
+ g_dir_close(gdir);
+ }
+ g_free(config);
+ return -1;
+}
+
static void
remove_plist(const gchar *name)
{
ghb_ui_update(ud, "hbfd", ghb_int64_value(0));
}
gval = ghb_settings_get_value(ud->settings, "default_source");
- ghb_settings_set_value (ud->settings, "source", gval);
+ ghb_settings_set_value (ud->settings, "scan_source", gval);
str = ghb_settings_get_string(ud->settings, "destination_dir");
ghb_ui_update(ud, "dest_dir", ghb_string_value(str));
{
ghb_dict_insert(dict, g_strdup(key), ghb_value_dup(gval));
}
- const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
+
+ const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP);
+ if (dir == NULL)
+ {
+ dir = ".";
+ }
+ ghb_dict_insert(dict,
+ g_strdup("ExportDirectory"), ghb_value_dup(ghb_string_value(dir)));
+
+ dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
if (dir == NULL)
{
dir = ".";
}
ghb_dict_insert(dict,
g_strdup("destination_dir"), ghb_value_dup(ghb_string_value(dir)));
+
+ ghb_dict_insert(dict,
+ g_strdup("SrtDir"), ghb_value_dup(ghb_string_value(dir)));
#if defined(_WIN32)
gchar *source;
2, def ? 2 : 0,
3, color,
4, description,
+ 5, type == PRESETS_BUILTIN ? 0 : 1,
-1);
if (def && piter)
{
presets_list_update_item(
signal_user_data_t *ud,
gint *indices,
- gint len)
+ gint len,
+ gboolean recurse)
{
GtkTreeView *treeview;
GtkTreeStore *store;
2, def ? 2 : 0,
3, color,
4, description,
+ 5, type == PRESETS_BUILTIN ? 0 : 1,
-1);
- if (folder)
+ if (recurse && folder)
{
ghb_presets_list_init(ud, indices, len);
}
2, def ? 2 : 0,
3, color,
4, description,
+ 5, type == PRESETS_BUILTIN ? 0 : 1,
-1);
if (folder)
{
void
ghb_save_queue(GValue *queue)
{
- store_plist(queue, "queue");
+ pid_t pid;
+ char *path;
+
+ pid = getpid();
+ path = g_strdup_printf ("queue.%d", pid);
+ store_plist(queue, path);
+ g_free(path);
}
GValue*
ghb_load_queue()
{
- return load_plist("queue");
+ GValue *queue;
+ pid_t pid;
+ char *path;
+
+ pid = getpid();
+ path = g_strdup_printf ("queue.%d", pid);
+ queue = load_plist(path);
+ g_free(path);
+ return queue;
+}
+
+GValue*
+ghb_load_old_queue(int pid)
+{
+ GValue *queue;
+ char *path;
+
+ path = g_strdup_printf ("queue.%d", pid);
+ queue = load_plist(path);
+ g_free(path);
+ return queue;
+}
+
+void
+ghb_remove_old_queue_file(int pid)
+{
+ char *path;
+
+ path = g_strdup_printf ("queue.%d", pid);
+ remove_plist(path);
+ g_free(path);
}
void
ghb_remove_queue_file()
{
- remove_plist("queue");
+ pid_t pid;
+ char *path;
+
+ pid = getpid();
+ path = g_strdup_printf ("queue.%d", pid);
+ remove_plist(path);
+ g_free(path);
}
typedef struct
{
{"AAC (faac)", "faac"},
{"AAC (CoreAudio)", "faac"},
- {"AC3 Passthru", "ac3"},
+ {"AC3 Passthru", "ac3pass"},
+ {"DTS Passthru", "dtspass"},
{"MP3 (lame)", "lame"},
{"Vorbis (vorbis)", "vorbis"},
{NULL,NULL}
value_map_t container_xlat[] =
{
{"MP4 file", "mp4"},
- {"M4V file", "m4v"},
+ {"M4V file", "mp4"},
{"MKV file", "mkv"},
{"AVI file", "mkv"},
{"OGM file", "mkv"},
{"10", "10"},
{"12", "12"},
{"15", "15"},
- {"23.976", "23.976"},
+ {"23.976 (NTSC Film)", "23.976"},
{"24", "24"},
- {"25", "25"},
- {"29.97", "29.97"},
+ {"25 (PAL Film/Video)", "25"},
+ {"29.97 (NTSC Video)", "29.97"},
{NULL, NULL}
};
value_map_t deint_xlat[] =
{
- {"0", "none"},
+ {"0", "off"},
{"1", "custom"},
{"2", "fast"},
{"3", "slow"},
value_map_t denoise_xlat[] =
{
- {"0", "none"},
+ {"0", "off"},
{"1", "custom"},
{"2", "weak"},
{"3", "medium"},
value_map_t detel_xlat[] =
{
- {"0", "none"},
+ {"0", "off"},
{"1", "custom"},
{"2", "default"},
{NULL, NULL}
value_map_t decomb_xlat[] =
{
- {"0", "none"},
+ {"0", "off"},
{"1", "custom"},
{"2", "default"},
{NULL, NULL}
{
if (strcmp(str, ghb_language_table[ii].iso639_2) == 0)
{
- gval = ghb_string_value_new(ghb_language_table[ii].eng_name);
+ const gchar *lang;
+
+ if (ghb_language_table[ii].native_name[0] != 0)
+ lang = ghb_language_table[ii].native_name;
+ else
+ lang = ghb_language_table[ii].eng_name;
+
+ gval = ghb_string_value_new(lang);
g_free(str);
return gval;
}
str = ghb_value_string(mac_val);
for (ii = 0; ghb_language_table[ii].eng_name; ii++)
{
- if (strcmp(str, ghb_language_table[ii].eng_name) == 0)
+ if ((strcmp(str, ghb_language_table[ii].eng_name) == 0) ||
+ (strcmp(str, ghb_language_table[ii].native_name) == 0))
{
gval = ghb_string_value_new(ghb_language_table[ii].iso639_2);
g_free(str);
if (gval)
ghb_dict_insert(dict, g_strdup(key), gval);
+
GValue *sdeflist;
GValue *sdefaults;
GValue *slist;
gval = import_value_xlat2(adefaults, mix_xlat, key, mac_val);
if (gval)
ghb_dict_insert(adict, g_strdup(key), gval);
+
+ mac_val = ghb_dict_lookup(adict, "AudioTrackDRCSlider");
+ if (mac_val != NULL)
+ {
+ gdouble drc;
+ drc = ghb_value_double(mac_val);
+ if (drc < 1.0 && drc > 0.0)
+ {
+ ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
+ ghb_double_value_new(0.0));
+ }
+ }
}
}
}
{
gboolean uses_max;
gint uses_pic;
- gint par, par_width, par_height;
+ gint par;
gint vqtype;
g_debug("import_xlat_preset ()");
preset_dict_get_value(dict, "UsesPictureSettings"));
par = ghb_value_int(preset_dict_get_value(dict, "PicturePAR"));
vqtype = ghb_value_int(preset_dict_get_value(dict, "VideoQualityType"));
- par_width = ghb_value_int(preset_dict_get_value(dict, "PicturePARWidth"));
- par_height = ghb_value_int(preset_dict_get_value(dict, "PicturePARHeight"));
- ghb_dict_insert(dict, g_strdup("par_width"),
- ghb_int_value_new(par_width));
- ghb_dict_insert(dict, g_strdup("par_height"),
- ghb_int_value_new(par_height));
if (uses_max || uses_pic == 2)
{
} break;
}
// VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
+ // *note: target is no longer used
switch (vqtype)
{
case 0:
{
- ghb_dict_insert(dict, g_strdup("vquality_type_target"),
- ghb_boolean_value_new(TRUE));
ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
- ghb_boolean_value_new(FALSE));
+ ghb_boolean_value_new(TRUE));
ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
ghb_boolean_value_new(FALSE));
} break;
case 1:
{
- ghb_dict_insert(dict, g_strdup("vquality_type_target"),
- ghb_boolean_value_new(FALSE));
ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
ghb_boolean_value_new(TRUE));
ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
} break;
case 2:
{
- ghb_dict_insert(dict, g_strdup("vquality_type_target"),
- ghb_boolean_value_new(FALSE));
ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
ghb_boolean_value_new(FALSE));
ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
} break;
default:
{
- ghb_dict_insert(dict, g_strdup("vquality_type_target"),
- ghb_boolean_value_new(FALSE));
ghb_dict_insert(dict, g_strdup("vquality_type_bitrate"),
ghb_boolean_value_new(FALSE));
ghb_dict_insert(dict, g_strdup("vquality_type_constant"),
ghb_boolean_value_new(TRUE));
} break;
}
+
import_value_xlat(dict);
+ GValue *mode = ghb_dict_lookup(dict, "VideoFramerateMode");
+ if (mode == NULL)
+ {
+ GValue *fr = ghb_dict_lookup(dict, "VideoFramerate");
+ if (fr)
+ {
+ gchar *str;
+ gboolean pfr = FALSE;
+ GValue *pfr_val = ghb_dict_lookup(dict, "VideoFrameratePFR");
+ if (pfr_val)
+ {
+ pfr = ghb_value_boolean(pfr_val);
+ }
+ str = ghb_value_string(fr);
+ if (strcmp(str, "source") == 0)
+ {
+ ghb_dict_insert(dict, g_strdup("VideoFramerateCFR"),
+ ghb_boolean_value_new(FALSE));
+ ghb_dict_insert(dict, g_strdup("VideoFramerateVFR"),
+ ghb_boolean_value_new(TRUE));
+ }
+ else if (!pfr)
+ {
+ ghb_dict_insert(dict, g_strdup("VideoFramerateCFR"),
+ ghb_boolean_value_new(TRUE));
+ ghb_dict_insert(dict, g_strdup("VideoFramerateVFR"),
+ ghb_boolean_value_new(FALSE));
+ }
+ else
+ {
+ ghb_dict_insert(dict, g_strdup("VideoFramerateCFR"),
+ ghb_boolean_value_new(FALSE));
+ ghb_dict_insert(dict, g_strdup("VideoFramerateVFR"),
+ ghb_boolean_value_new(FALSE));
+ }
+ g_free(str);
+ }
+ }
+ else
+ {
+ gchar *str;
+ str = ghb_value_string(mode);
+ if (strcmp(str, "cfr") == 0)
+ {
+ ghb_dict_insert(dict, g_strdup("VideoFramerateCFR"),
+ ghb_boolean_value_new(TRUE));
+ ghb_dict_insert(dict, g_strdup("VideoFrameratePFR"),
+ ghb_boolean_value_new(FALSE));
+ ghb_dict_insert(dict, g_strdup("VideoFramerateVFR"),
+ ghb_boolean_value_new(FALSE));
+ }
+ else if (strcmp(str, "pfr") == 0)
+ {
+ ghb_dict_insert(dict, g_strdup("VideoFramerateCFR"),
+ ghb_boolean_value_new(FALSE));
+ ghb_dict_insert(dict, g_strdup("VideoFrameratePFR"),
+ ghb_boolean_value_new(TRUE));
+ ghb_dict_insert(dict, g_strdup("VideoFramerateVFR"),
+ ghb_boolean_value_new(FALSE));
+ }
+ else
+ {
+ ghb_dict_insert(dict, g_strdup("VideoFramerateCFR"),
+ ghb_boolean_value_new(FALSE));
+ ghb_dict_insert(dict, g_strdup("VideoFrameratePFR"),
+ ghb_boolean_value_new(FALSE));
+ ghb_dict_insert(dict, g_strdup("VideoFramerateVFR"),
+ ghb_boolean_value_new(TRUE));
+ }
+ g_free(str);
+ }
+
gdouble vquality;
const GValue *gval;
vquality = ghb_value_double(preset_dict_get_value(dict, "VideoQualitySlider"));
- if (vquality < 1.0)
+ if (vquality > 0.0 && vquality < 1.0)
{
gint vcodec;
static void
export_xlat_preset(GValue *dict)
{
- gboolean autoscale, target, br, constant;
- gint par_width, par_height;
+ gboolean autoscale, br, constant;
g_debug("export_xlat_prest ()");
autoscale = ghb_value_boolean(preset_dict_get_value(dict, "autoscale"));
- target = ghb_value_boolean(
- preset_dict_get_value(dict, "vquality_type_target"));
br = ghb_value_boolean(
preset_dict_get_value(dict, "vquality_type_bitrate"));
constant = ghb_value_boolean(
preset_dict_get_value(dict, "vquality_type_constant"));
- par_width = ghb_value_int(
- preset_dict_get_value(dict, "par_width"));
- par_height = ghb_value_int(
- preset_dict_get_value(dict, "par_height"));
if (autoscale)
ghb_dict_insert(dict, g_strdup("UsesPictureSettings"),
ghb_int_value_new(1));
// VideoQualityType/0/1/2 - vquality_type_/target/bitrate/constant
- if (target)
- {
- ghb_dict_insert(dict, g_strdup("VideoQualityType"),
- ghb_int_value_new(0));
- }
- else if (br)
+ // *note: target is no longer used
+ if (br)
{
ghb_dict_insert(dict, g_strdup("VideoQualityType"),
ghb_int_value_new(1));
ghb_dict_insert(dict, g_strdup("VideoQualityType"),
ghb_int_value_new(2));
}
- ghb_dict_insert(dict, g_strdup("PicturePARWidth"),
- ghb_int_value_new(par_width));
- ghb_dict_insert(dict, g_strdup("PicturePARHeight"),
- ghb_int_value_new(par_height));
+
+ if (ghb_value_boolean(preset_dict_get_value(dict, "VideoFramerateCFR")))
+ {
+ ghb_dict_insert(dict, g_strdup("VideoFramerateMode"),
+ ghb_string_value_new("cfr"));
+ }
+ else if (ghb_value_boolean(preset_dict_get_value(dict, "VideoFrameratePFR")))
+ {
+ ghb_dict_insert(dict, g_strdup("VideoFramerateMode"),
+ ghb_string_value_new("pfr"));
+ }
+ else
+ {
+ ghb_dict_insert(dict, g_strdup("VideoFramerateMode"),
+ ghb_string_value_new("vfr"));
+ }
+
+ GValue *alist, *adict;
+ gint count, ii;
+
+ alist = ghb_dict_lookup(dict, "AudioList");
+ count = ghb_array_len(alist);
+ for (ii = 0; ii < count; ii++)
+ {
+ gdouble drc;
+
+ adict = ghb_array_get_nth(alist, ii);
+ drc = ghb_value_double(
+ preset_dict_get_value(adict, "AudioTrackDRCSlider"));
+ if (drc < 1.0 && drc > 0.0)
+ {
+ ghb_dict_insert(adict, g_strdup("AudioTrackDRCSlider"),
+ ghb_double_value_new(0.0));
+ }
+ }
+
+ GValue *internal;
+ GHashTableIter iter;
+ gchar *key;
+ GValue *value;
+ internal = plist_get_dict(internalPlist, "XlatPresets");
+ ghb_dict_iter_init(&iter, internal);
+ // middle (void*) cast prevents gcc warning "defreferencing type-punned
+ // pointer will break strict-aliasing rules"
+ while (g_hash_table_iter_next(
+ &iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
+ {
+ ghb_dict_remove(dict, key);
+ }
+
+ // remove obsolete keys
ghb_dict_remove(dict, "UsesMaxPictureSettings");
- ghb_dict_remove(dict, "autoscale");
- ghb_dict_remove(dict, "vquality_type_target");
- ghb_dict_remove(dict, "vquality_type_bitrate");
- ghb_dict_remove(dict, "vquality_type_constant");
- ghb_dict_remove(dict, "par_width");
- ghb_dict_remove(dict, "par_height");
+ ghb_dict_remove(dict, "VFR");
+ ghb_dict_remove(dict, "VideoFrameratePFR");
+
export_value_xlat(dict);
}
GHashTableIter iter;
gchar *key;
GValue *value;
- gboolean autoscale;
gint *indices, len, count;
gint *def_indices, def_len;
const gchar *name;
}
}
current_preset = dict;
- autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
ghb_settings_set_int64(ud->settings, "Type", PRESETS_CUSTOM);
ghb_settings_set_int64(ud->settings, "PresetBuildNumber", hb_get_build(NULL));
&iter, (gpointer*)(void*)&key, (gpointer*)(void*)&value))
{
const GValue *gval;
- gchar *key2;
- key2 = key;
- if (!autoscale)
- {
- if (strcmp(key, "PictureWidth") == 0)
- {
- key2 = "scale_width";
- }
- else if (strcmp(key, "PictureHeight") == 0)
- {
- key2 = "scale_height";
- }
- }
- gval = ghb_settings_get_value(ud->settings, key2);
+ gval = ghb_settings_get_value(ud->settings, key);
if (gval == NULL)
{
continue;
ghb_dict_insert(dict, g_strdup("Default"),
ghb_boolean_value_new(FALSE));
}
- presets_list_update_item(ud, indices, len);
+ presets_list_update_item(ud, indices, len, FALSE);
}
else
{
ghb_boolean_value_new(FALSE));
presets_list_insert(ud, indices, len);
}
+ if (!ghb_settings_get_boolean( ud->settings, "PictureWidthEnable"))
+ {
+ ghb_dict_remove(dict, "PictureWidth");
+ }
+ if (!ghb_settings_get_boolean( ud->settings, "PictureHeightEnable"))
+ {
+ ghb_dict_remove(dict, "PictureHeight");
+ }
+ ghb_dict_insert(dict, g_strdup("autoscale"),
+ ghb_boolean_value_new(
+ !ghb_settings_get_boolean( ud->settings, "PictureWidthEnable") &&
+ !ghb_settings_get_boolean( ud->settings, "PictureHeightEnable")
+ )
+ );
store_presets();
ud->dont_clear_presets = TRUE;
// Make the new preset the selected item
ghb_dict_insert(dict, g_strdup("PresetDescription"),
ghb_value_dup(preset_dict_get_value(
ud->settings, "PresetDescription")));
+ presets_list_update_item(ud, indices, len, FALSE);
g_free(indices);
+ store_presets();
return;
}
else
g_debug("update_subtitle_presets");
const GValue *subtitle_list, *subtitle;
GValue *slist, *dict;
- gint count, ii;
+ gint count, ii, source;
subtitle_list = ghb_settings_get_value(ud->settings, "subtitle_list");
slist = ghb_array_value_new(8);
for (ii = 0; ii < count; ii++)
{
subtitle = ghb_array_get_nth(subtitle_list, ii);
- dict = ghb_value_dup(subtitle);
- ghb_array_append(slist, dict);
+ source = ghb_settings_get_int(subtitle, "SubtitleSource");
+ if (source != SRTSUB)
+ {
+ dict = ghb_value_dup(subtitle);
+ ghb_array_append(slist, dict);
+ }
}
- ghb_settings_set_value(ud->settings, "SubtitleList", slist);
+ ghb_settings_take_value(ud->settings, "SubtitleList", slist);
}
-void
-enforce_preset_type(signal_user_data_t *ud, const GValue *path)
+G_MODULE_EXPORT void
+presets_menu_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
{
- gint *indices, len;
- GtkWidget *normal, *folder;
- gboolean fold;
+ GtkMenu *menu;
- normal = GHB_WIDGET(ud->builder, "preset_type_normal");
- folder = GHB_WIDGET(ud->builder, "preset_type_folder");
- indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
- if (indices)
+ menu = GTK_MENU(GHB_WIDGET(ud->builder, "presets_menu"));
+ gtk_menu_popup(menu, NULL, NULL, NULL, NULL, 1,
+ gtk_get_current_event_time());
+}
+
+G_MODULE_EXPORT void
+preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
+{
+ GtkWidget *dialog;
+ GtkResponseType response;
+ gchar *exportDir;
+ gchar *filename;
+ GtkFileFilter *filter;
+
+ g_debug("preset_import_clicked_cb ()");
+
+ dialog = gtk_file_chooser_dialog_new("Import Preset", NULL,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ filter = gtk_file_filter_new();
+ gtk_file_filter_set_name(filter, "All (*)");
+ gtk_file_filter_add_pattern(filter, "*");
+ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
+
+ filter = gtk_file_filter_new();
+ gtk_file_filter_set_name(filter, "Presets (*.plist)");
+ gtk_file_filter_add_pattern(filter, "*.plist");
+ gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), filter);
+ gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
+
+ exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
+ if (exportDir == NULL || exportDir[0] == '\0')
{
- fold = ghb_presets_get_folder(presetsPlist, indices, len);
- if (fold)
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(folder),
- TRUE);
- else
- gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(normal),
- TRUE);
- gtk_widget_set_sensitive(folder, fold);
- gtk_widget_set_sensitive(normal, !fold);
- g_free(indices);
+ exportDir = g_strdup(".");
+ }
+ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
+ g_free(exportDir);
+
+ response = gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_hide(dialog);
+ if (response == GTK_RESPONSE_ACCEPT)
+ {
+ GValue *dict, *array;
+ gchar *dir;
+ gint count, ii;
+
+ filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+
+ // import the preset
+ if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR))
+ {
+ gtk_widget_destroy(dialog);
+ g_free(filename);
+ return;
+ }
+ array = ghb_plist_parse_file(filename);
+
+ import_xlat_presets(array);
+ presets_clear_default(array);
+ presets_customize(array);
+
+ count = ghb_array_len(array);
+ for (ii = 0; ii < count; ii++)
+ {
+ GValue *path, *name;
+ gint *indices, len;
+ gint index = 1;
+
+ dict = ghb_array_get_nth(array, ii);
+ path = ghb_array_value_new(1);
+ name = ghb_value_dup(ghb_dict_lookup(dict, "PresetName"));
+ ghb_array_append(path, name);
+ indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
+ // Modify the preset name till we make it unique
+ while (indices != NULL)
+ {
+ gchar *str = ghb_value_string(name);
+
+ ghb_value_free(path);
+ g_free(indices);
+
+ str = g_strdup_printf("%s %d", str, index);
+ path = ghb_array_value_new(1);
+ name = ghb_string_value_new(str);
+ ghb_array_append(path, name);
+ g_free(str);
+
+ index++;
+ indices = ghb_preset_indices_from_path(presetsPlist, path, &len);
+ }
+ ghb_dict_insert(dict, g_strdup("PresetName"), ghb_value_dup(name));
+ indices = presets_find_pos(path, PRESETS_CUSTOM, &len);
+ ghb_presets_insert(presetsPlist, ghb_value_dup(dict), indices, len);
+ presets_list_insert(ud, indices, len);
+ ghb_value_free(path);
+ }
+ ghb_value_free(array);
+
+ exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
+ dir = g_path_get_dirname(filename);
+ if (strcmp(dir, exportDir) != 0)
+ {
+ ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
+ ghb_pref_save(ud->settings, "ExportDirectory");
+ }
+ g_free(filename);
+ g_free(exportDir);
+ g_free(dir);
+ store_presets();
+ }
+ gtk_widget_destroy(dialog);
+}
+
+G_MODULE_EXPORT void
+preset_export_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
+{
+ GtkWidget *dialog;
+ GtkResponseType response;
+ GValue *preset;
+ const gchar *name = "";
+ gint count, *indices, len;
+ gchar *exportDir;
+ gchar *filename;
+
+ g_debug("preset_export_clicked_cb ()");
+ preset = ghb_settings_get_value (ud->settings, "preset_selection");
+ if (preset == NULL)
+ return;
+
+ count = ghb_array_len(preset);
+ if (count <= 0)
+ return;
+
+ name = g_value_get_string(ghb_array_get_nth(preset, count-1));
+
+ dialog = gtk_file_chooser_dialog_new("Export Preset", NULL,
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
+ if (exportDir == NULL || exportDir[0] == '\0')
+ {
+ exportDir = g_strdup(".");
+ }
+ filename = g_strdup_printf("%s.plist", name);
+ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), exportDir);
+ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), filename);
+ g_free(filename);
+ g_free(exportDir);
+
+ indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
+ if (indices == NULL)
+ return;
+
+ response = gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_hide(dialog);
+ if (response == GTK_RESPONSE_ACCEPT)
+ {
+ GValue *export, *dict, *array;
+ FILE *file;
+ gchar *dir;
+
+ filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+
+ // export the preset
+ dict = presets_get_dict(presetsPlist, indices, len);
+
+ export = ghb_value_dup(dict);
+ array = ghb_array_value_new(1);
+ ghb_array_append(array, export);
+ presets_clear_default(array);
+ presets_customize(array);
+ export_xlat_presets(array);
+
+ file = g_fopen(filename, "w");
+ if (file != NULL)
+ {
+ ghb_plist_write(file, array);
+ fclose(file);
+ }
+ ghb_value_free(array);
+
+ exportDir = ghb_settings_get_string(ud->settings, "ExportDirectory");
+ dir = g_path_get_dirname(filename);
+ if (strcmp(dir, exportDir) != 0)
+ {
+ ghb_settings_set_string(ud->settings, "ExportDirectory", dir);
+ ghb_pref_save(ud->settings, "ExportDirectory");
+ }
+ g_free(exportDir);
+ g_free(dir);
+ g_free(filename);
}
+ gtk_widget_destroy(dialog);
+ g_free(indices);
+}
+
+G_MODULE_EXPORT void
+presets_new_folder_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
+{
+ GtkWidget *dialog;
+ GtkEntry *entry;
+ GtkTextView *desc;
+ GtkResponseType response;
+ GValue *preset, *dict;
+ const gchar *name = "";
+ const gchar *description = "";
+ gint count, *indices, len;
+
+ g_debug("presets_new_folder_clicked_cb ()");
+ preset = ghb_settings_get_value (ud->settings, "preset_selection");
+
+ count = ghb_array_len(preset);
+ if (count > 0)
+ name = g_value_get_string(ghb_array_get_nth(preset, count-1));
else
+ count = 1;
+
+ indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
+ dict = presets_get_dict(presetsPlist, indices, len);
+ if (dict != NULL)
{
- gtk_widget_set_sensitive(folder, TRUE);
- gtk_widget_set_sensitive(normal, TRUE);
+ description = g_value_get_string(
+ ghb_dict_lookup(dict, "PresetDescription"));
+ ghb_ui_update(ud, "FolderDescription", ghb_string_value(description));
}
+
+ desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "FolderDescription"));
+ dialog = GHB_WIDGET(ud->builder, "preset_new_folder_dialog");
+ entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "FolderName"));
+ gtk_entry_set_text(entry, name);
+ response = gtk_dialog_run(GTK_DIALOG(dialog));
+ gtk_widget_hide(dialog);
+ if (response == GTK_RESPONSE_OK)
+ {
+ // save the preset
+ const gchar *name = gtk_entry_get_text(entry);
+ GValue *dest;
+
+ if (count > MAX_NESTED_PRESET-1)
+ count = MAX_NESTED_PRESET-1;
+
+ dest = ghb_array_value_new(MAX_NESTED_PRESET);
+ if (indices != NULL)
+ {
+ gint ptype;
+
+ ptype = ghb_presets_get_type(presetsPlist, indices, len);
+ if (ptype == PRESETS_CUSTOM)
+ {
+ ghb_array_copy(dest, preset, count-1);
+ }
+ }
+ ghb_array_append(dest, ghb_string_value_new(name));
+ GValue *val = ghb_widget_value(GTK_WIDGET(desc));
+ ghb_settings_set_value(ud->settings, "PresetDescription", val);
+ folder_save(ud, dest);
+ ghb_value_free(dest);
+ }
+ if (indices != NULL)
+ g_free(indices);
}
G_MODULE_EXPORT void
name = g_value_get_string(ghb_array_get_nth(preset, count-1));
else
count = 1;
- // Clear the description
+
desc = GTK_TEXT_VIEW(GHB_WIDGET(ud->builder, "PresetDescription"));
+ int width = ghb_settings_get_int(ud->settings, "PictureWidth");
+ int height = ghb_settings_get_int(ud->settings, "PictureHeight");
+ gboolean autoscale = ghb_settings_get_boolean(ud->settings, "autoscale");
+ ghb_ui_update(ud, "PictureWidthEnable",
+ ghb_boolean_value(width!=0&&!autoscale));
+ ghb_ui_update(ud, "PictureHeightEnable",
+ ghb_boolean_value(height!=0&&!autoscale));
+ if (!width)
+ {
+ width = ghb_settings_get_int(ud->settings, "scale_width");
+ ghb_ui_update(ud, "PictureWidth", ghb_int_value(width));
+ }
+ if (!height)
+ {
+ height = ghb_settings_get_int(ud->settings, "scale_height");
+ ghb_ui_update(ud, "PictureHeight", ghb_int_value(height));
+ }
dialog = GHB_WIDGET(ud->builder, "preset_save_dialog");
entry = GTK_ENTRY(GHB_WIDGET(ud->builder, "PresetName"));
gtk_entry_set_text(entry, name);
- enforce_preset_type(ud, preset);
response = gtk_dialog_run(GTK_DIALOG(dialog));
gtk_widget_hide(dialog);
if (response == GTK_RESPONSE_OK)
const gchar *name = gtk_entry_get_text(entry);
GValue *dest;
- if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
- {
- if (count > MAX_NESTED_PRESET-1)
- {
- count = MAX_NESTED_PRESET-1;
- }
- }
dest = ghb_array_value_new(MAX_NESTED_PRESET);
indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
if (indices)
{
ghb_array_copy(dest, preset, count-1);
}
+ g_free(indices);
}
ghb_array_append(dest, ghb_string_value_new(name));
ghb_widget_to_setting(ud->settings, GTK_WIDGET(desc));
- if (ghb_settings_get_boolean(ud->settings, "preset_type_folder"))
- {
- folder_save(ud, dest);
- }
- else
- {
- // Construct the audio settings presets from the current audio list
- update_audio_presets(ud);
- update_subtitle_presets(ud);
- settings_save(ud, dest);
- }
+
+ // Construct the audio settings presets from the current audio list
+ update_audio_presets(ud);
+ update_subtitle_presets(ud);
+ settings_save(ud, dest);
ghb_value_free(dest);
}
}
}
G_MODULE_EXPORT void
-preset_name_changed_cb(GtkWidget *entry, signal_user_data_t *ud)
-{
- gchar *name;
- GValue *preset, *dest;
- gint count;
-
- preset = ghb_settings_get_value (ud->settings, "preset_selection");
- name = ghb_widget_string(entry);
- dest = ghb_value_dup(preset);
- count = ghb_array_len(dest);
- ghb_array_replace(dest, count-1, ghb_string_value_new(name));
- enforce_preset_type(ud, dest);
- ghb_value_free(dest);
-}
-
-G_MODULE_EXPORT void
presets_restore_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud)
{
GValue *preset;
dstpath = gtk_tree_model_get_path (dstmodel, &iter);
dst_indices = gtk_tree_path_get_indices(dstpath);
dst_len = gtk_tree_path_get_depth(dstpath);
- presets_list_update_item(ud, dst_indices, dst_len);
+ presets_list_update_item(ud, dst_indices, dst_len, TRUE);
gtk_tree_path_free(dstpath);
store_presets();
}
}
+void
+ghb_refresh_preset(signal_user_data_t *ud)
+{
+ ghb_title_info_t tinfo;
+ GValue *preset;
+ gint *indices, len;
+
+ g_debug("ghb_refresh_preset ()");
+ preset = ghb_settings_get_value(ud->settings, "preset_selection");
+ indices = ghb_preset_indices_from_path(presetsPlist, preset, &len);
+ if (indices)
+ {
+ gboolean folder;
+
+ folder = ghb_presets_get_folder(presetsPlist, indices, len);
+ if (!folder)
+ {
+ ud->dont_clear_presets = TRUE;
+ ud->scale_busy = TRUE;
+ // Temporarily set the video_quality range to (0,100)
+ // This is needed so the video_quality value does not get
+ // truncated when set. The range will be readjusted below
+ GtkWidget *qp = GHB_WIDGET(ud->builder, "VideoQualitySlider");
+ gtk_range_set_range (GTK_RANGE(qp), 0, 100);
+ gtk_scale_set_digits(GTK_SCALE(qp), 3);
+ // Clear the audio list prior to changing the preset. Existing
+ // audio can cause the container extension to be automatically
+ // changed when it shouldn't be
+ ghb_clear_audio_list(ud);
+ ghb_set_preset_from_indices(ud, indices, len);
+ gint titleindex;
+ titleindex = ghb_settings_combo_int(ud->settings, "title");
+ ghb_set_pref_audio(titleindex, ud);
+ ghb_set_pref_subtitle(titleindex, ud);
+ ghb_settings_set_boolean(ud->settings, "preset_modified", FALSE);
+ if (ghb_get_title_info (&tinfo, titleindex))
+ {
+ preset_update_title_deps(ud, &tinfo);
+ }
+ ud->scale_busy = FALSE;
+ ghb_set_scale (ud, GHB_PIC_KEEP_PAR|GHB_PIC_USE_MAX);
+ ud->dont_clear_presets = FALSE;
+
+ gdouble vqmin, vqmax, step, page;
+ gint digits;
+ gboolean inverted;
+
+ ghb_vquality_range(ud, &vqmin, &vqmax, &step,
+ &page, &digits, &inverted);
+ gtk_range_set_range (GTK_RANGE(qp), vqmin, vqmax);
+ gtk_range_set_increments (GTK_RANGE(qp), step, page);
+ gtk_scale_set_digits(GTK_SCALE(qp), digits);
+ gtk_range_set_inverted (GTK_RANGE(qp), inverted);
+
+ gchar *text;
+ gint crop[4];
+ GtkWidget *crop_widget;
+ crop[0] = ghb_settings_get_int(ud->settings, "PictureTopCrop");
+ crop[1] = ghb_settings_get_int(ud->settings, "PictureBottomCrop");
+ crop[2] = ghb_settings_get_int(ud->settings, "PictureLeftCrop");
+ crop[3] = ghb_settings_get_int(ud->settings, "PictureRightCrop");
+ crop_widget = GHB_WIDGET (ud->builder, "crop_values");
+ text = g_strdup_printf("%d:%d:%d:%d",
+ crop[0], crop[1], crop[2], crop[3]);
+ gtk_label_set_text (GTK_LABEL(crop_widget), text);
+ g_free(text);
+ }
+ }
+}
+
G_MODULE_EXPORT void
presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_t *ud)
{
if (!folder)
{
ud->dont_clear_presets = TRUE;
+ ud->scale_busy = TRUE;
// Temporarily set the video_quality range to (0,100)
// This is needed so the video_quality value does not get
// truncated when set. The range will be readjusted below
// changed when it shouldn't be
ghb_clear_audio_list(ud);
ghb_set_preset_from_indices(ud, indices, len);
- gtk_tree_path_free(treepath);
gint titleindex;
titleindex = ghb_settings_combo_int(ud->settings, "title");
ghb_set_pref_audio(titleindex, ud);
{
preset_update_title_deps(ud, &tinfo);
}
- ghb_set_scale (ud, GHB_PIC_KEEP_PAR);
+ ud->scale_busy = FALSE;
+ ghb_set_scale (ud, GHB_PIC_KEEP_PAR|GHB_PIC_USE_MAX);
ud->dont_clear_presets = FALSE;
gdouble vqmin, vqmax, step, page;
gtk_label_set_text (GTK_LABEL(crop_widget), text);
g_free(text);
}
+ gtk_tree_path_free(treepath);
gtk_widget_set_sensitive(widget, TRUE);
}
else
g_debug("No selection??? Perhaps unselected.");
gtk_widget_set_sensitive(widget, FALSE);
}
+ if (ghb_settings_combo_int(ud->settings, "PtoPType") == 0)
+ {
+ gint start, end;
+ start = ghb_settings_get_int(ud->settings, "start_point");
+ end = ghb_settings_get_int(ud->settings, "end_point");
+ widget = GHB_WIDGET (ud->builder, "ChapterMarkers");
+ gtk_widget_set_sensitive(widget, TRUE);
+ if (start == end)
+ {
+ ud->dont_clear_presets = TRUE;
+ ghb_ui_update(ud, "ChapterMarkers", ghb_boolean_value(FALSE));
+ ud->dont_clear_presets = FALSE;
+ gtk_widget_set_sensitive(widget, FALSE);
+ }
+ }
}
void
}
}
+G_MODULE_EXPORT void
+preset_edited_cb(
+ GtkCellRendererText *cell,
+ gchar *path,
+ gchar *text,
+ signal_user_data_t *ud)
+{
+ GtkTreePath *treepath;
+ GtkTreeStore *store;
+ GtkTreeView *treeview;
+ GtkTreeIter iter;
+ gint *indices, len, count;
+ GValue *dict;
+ GValue *preset, *dest;
+
+ g_debug("preset_edited_cb ()");
+ g_debug("path (%s)", path);
+ g_debug("text (%s)", text);
+
+ preset = ghb_settings_get_value (ud->settings, "preset_selection");
+ dest = ghb_array_value_new(MAX_NESTED_PRESET);
+ count = ghb_array_len(preset);
+ ghb_array_copy(dest, preset, count-1);
+ ghb_array_append(dest, ghb_string_value_new(text));
+ indices = ghb_preset_indices_from_path(presetsPlist, dest, &len);
+ ghb_value_free(dest);
+ if (indices != NULL)
+ {
+ // Already exists
+ g_free(indices);
+ return;
+ }
+
+ treeview = GTK_TREE_VIEW(GHB_WIDGET(ud->builder, "presets_list"));
+ store = GTK_TREE_STORE(gtk_tree_view_get_model(treeview));
+ treepath = gtk_tree_path_new_from_string (path);
+ indices = gtk_tree_path_get_indices(treepath);
+ len = gtk_tree_path_get_depth(treepath);
+ gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, treepath);
+ gtk_tree_store_set(store, &iter, 0, text, -1);
+
+ dict = presets_get_dict(presetsPlist, indices, len);
+ ghb_dict_insert(dict, g_strdup("PresetName"), ghb_string_value_new(text));
+ store_presets();
+ gtk_tree_path_free (treepath);
+}
+