X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=gtk%2Fsrc%2Fpresets.c;h=66f69a748badedbb635503cb4b0fa06e12be09fe;hb=0884cb45aeeb60a46effe1d1056a61fe68300ea7;hp=5bd8786ddc4664caa471bd53067a95016c0a052c;hpb=019aa646f173cbd66cf9ac79e8139af1753149f2;p=handbrake-jp%2Fhandbrake-jp-git.git diff --git a/gtk/src/presets.c b/gtk/src/presets.c index 5bd8786d..66f69a74 100644 --- a/gtk/src/presets.c +++ b/gtk/src/presets.c @@ -11,6 +11,10 @@ * any later version. * */ +#include +#include +#include +#include #include #include #include @@ -902,6 +906,19 @@ preset_to_ui(signal_user_data_t *ud, GValue *dict) 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)); + } + } } void @@ -1112,6 +1129,135 @@ load_plist(const gchar *name) 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) { @@ -1202,7 +1348,7 @@ ghb_prefs_to_ui(signal_user_data_t *ud) 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)); @@ -1767,19 +1913,61 @@ remove_std_presets(signal_user_data_t *ud) 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 @@ -1855,7 +2043,7 @@ value_map_t mix_xlat[] = value_map_t deint_xlat[] = { - {"0", "none"}, + {"0", "off"}, {"1", "custom"}, {"2", "fast"}, {"3", "slow"}, @@ -1865,7 +2053,7 @@ value_map_t deint_xlat[] = value_map_t denoise_xlat[] = { - {"0", "none"}, + {"0", "off"}, {"1", "custom"}, {"2", "weak"}, {"3", "medium"}, @@ -1875,7 +2063,7 @@ value_map_t denoise_xlat[] = value_map_t detel_xlat[] = { - {"0", "none"}, + {"0", "off"}, {"1", "custom"}, {"2", "default"}, {NULL, NULL} @@ -1883,7 +2071,7 @@ value_map_t detel_xlat[] = value_map_t decomb_xlat[] = { - {"0", "none"}, + {"0", "off"}, {"1", "custom"}, {"2", "default"}, {NULL, NULL} @@ -1905,7 +2093,14 @@ export_lang_xlat2(GValue *lin_val) { 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; } @@ -1951,7 +2146,8 @@ import_lang_xlat2(GValue *mac_val) 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); @@ -2481,7 +2677,7 @@ import_xlat_preset(GValue *dict) 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; @@ -3152,7 +3348,7 @@ preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) g_debug("preset_import_clicked_cb ()"); - dialog = gtk_file_chooser_dialog_new("Export Preset", NULL, + 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, @@ -3195,7 +3391,6 @@ preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) return; } array = ghb_plist_parse_file(filename); - g_free(filename); import_xlat_presets(array); presets_clear_default(array); @@ -3245,8 +3440,10 @@ preset_import_clicked_cb(GtkWidget *xwidget, signal_user_data_t *ud) 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); } @@ -3889,6 +4086,74 @@ preset_update_title_deps(signal_user_data_t *ud, ghb_title_info_t *tinfo) } } +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; + // 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); + } + ghb_set_scale (ud, GHB_PIC_KEEP_PAR); + 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) { @@ -3928,7 +4193,6 @@ presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_ // 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); @@ -3965,6 +4229,7 @@ presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_ gtk_label_set_text (GTK_LABEL(crop_widget), text); g_free(text); } + gtk_tree_path_free(treepath); gtk_widget_set_sensitive(widget, TRUE); } else @@ -3972,6 +4237,21 @@ presets_list_selection_changed_cb(GtkTreeSelection *selection, signal_user_data_ 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 @@ -4040,12 +4320,28 @@ preset_edited_cb( GtkTreeStore *store; GtkTreeView *treeview; GtkTreeIter iter; - gint *indices, len; + 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);