- desc = g_key_file_get_string(customKeyFile, custom[ii], "preset_description", NULL);
- data->description = desc;
- presetsList = g_list_append(presetsList, data);
- }
- g_strfreev(custom);
- g_strfreev(standard);
-}
-
-static void
-store_key_file(GKeyFile *key_file, const gchar *name)
-{
- gchar *settingsString;
- const gchar *dir;
- gsize length;
- gchar *config;
- gint fd;
-
- g_debug("store_key_file ()\n");
- settingsString = g_key_file_to_data(key_file, &length, NULL);
-
- dir = g_get_user_config_dir();
- config = g_strdup_printf ("%s/ghb", dir);
- if (!g_file_test(config, G_FILE_TEST_IS_DIR))
- {
- g_mkdir (config, 0755);
- }
- g_free(config);
- config = g_strdup_printf ("%s/ghb/%s", dir, name);
- fd = g_open(config, O_RDWR|O_CREAT|O_TRUNC, 0777);
- write(fd, settingsString, length);
- close(fd);
- g_debug("prefs:\n%s\n", settingsString);
- g_free(settingsString);
-}
-
-void
-ghb_prefs_to_ui(signal_user_data_t *ud)
-{
- const gchar *str;
-
- str = ghb_settings_get_string(ud->settings, "default_source");
- ghb_settings_set_string (ud->settings, "source", str);
- str = ghb_settings_get_string(ud->settings, "destination_dir");
-
- gchar *path = g_strdup_printf ("%s/new_video.mp4", str);
- ghb_ui_update(ud, "destination", path);
- g_free(path);
-}
-
-static gboolean prefs_initializing = FALSE;
-
-void
-ghb_prefs_save(GHashTable *settings)
-{
- gint ii;
- const gchar *value;
- gchar **keys;
- gsize length;
-
- if (prefs_initializing) return;
- keys = g_key_file_get_keys(internalKeyFile, "Preferences", &length, NULL);
- if (keys != NULL)
- {
- for (ii = 0; keys[ii] != NULL; ii++)
- {
- value = ghb_settings_get_string(settings, keys[ii]);
- if (value != NULL)
- {
- g_key_file_set_value(prefsKeyFile, "Preferences", keys[ii], value);
- }
- }
- g_strfreev(keys);
- store_key_file(prefsKeyFile, "preferences");
- }
-}
-
-#if 0
-static void
-dump_key_file(GKeyFile *keyFile, const gchar *section)
-{
- gint ii;
- gchar **keys;
- gsize length;
-
- // Get defaults from internal defaults
- keys = g_key_file_get_keys(keyFile, section, &length, NULL);
- if (keys != NULL)
- {
- for (ii = 0; keys[ii] != NULL; ii++)
- {
- gchar *str;
-
- str = g_key_file_get_string(keyFile, section, keys[ii], NULL);
- if (str != NULL)
- {
- g_message("Preference: key (%s) -- str (%s)\n", keys[ii], str);
- g_free(str);
- }
- else
- {
- g_message("Preference: key (%s) -- str **none**\n", keys[ii]);
- }
- }
- g_strfreev(keys);
- }
- else
- {
- g_message("no keys");
- }
-}
-#endif
-
-void
-ghb_prefs_load(signal_user_data_t *ud)
-{
- gint ii;
- const gchar *dir;
- gchar *config;
- gchar *value;
- gchar **keys;
- gsize length;
- gboolean res;
-
- prefs_initializing = TRUE;
- internalKeyFile = g_key_file_new();
- res = g_key_file_load_from_data( internalKeyFile, defaultSettings,
- sizeof(defaultSettings), G_KEY_FILE_NONE, NULL);
- if (!res)
- g_warning("Failed to initialize internal defaults\n");
-
- keys = g_key_file_get_keys(internalKeyFile, "Initialization", &length, NULL);
- if (keys != NULL)
- {
- gint ii;
- for (ii = 0; keys[ii] != NULL; ii++)
- {
- gchar *str;
-
- g_debug("key (%s)\n", keys[ii]);
- str = g_key_file_get_string(internalKeyFile, "Initialization", keys[ii], NULL);
- if (str != NULL)
- {
- g_debug("Initialization: key (%s) -- str (%s)\n", keys[ii], str);
- ghb_settings_set_string(ud->settings, keys[ii], str);
- ghb_ui_update(ud, keys[ii], str);
- g_free(str);
- }
- }
- g_strfreev(keys);
- }
- prefsKeyFile = g_key_file_new();
- dir = g_get_user_config_dir();
- config = g_strdup_printf ("%s/ghb/preferences", dir);
- if (g_file_test(config, G_FILE_TEST_IS_REGULAR))
- {
- g_key_file_load_from_file( prefsKeyFile, config, G_KEY_FILE_KEEP_COMMENTS, NULL);
- }
- value = g_key_file_get_value(prefsKeyFile, "Preferences", "version", NULL);
- if (value == NULL)
- {
- gint ii;
-
- // Get defaults from internal defaults
- keys = g_key_file_get_keys(internalKeyFile, "Preferences", &length, NULL);
- if (keys != NULL)
- {
- for (ii = 0; keys[ii] != NULL; ii++)
- {
- gchar *str;
-
- str = g_key_file_get_string(internalKeyFile, "Preferences", keys[ii], NULL);
- if (str != NULL)
- {
- g_debug("Preference: key (%s) -- str (%s)\n", keys[ii], str);
- g_key_file_set_value(prefsKeyFile, "Preferences", keys[ii], str);
- g_free(str);
- }
- }
- g_strfreev(keys);
- }
- const gchar *dir = g_get_user_special_dir (G_USER_DIRECTORY_VIDEOS);
- g_key_file_set_value(prefsKeyFile, "Preferences", "destination_dir", dir);
- store_key_file(prefsKeyFile, "preferences");
- }
- g_free(config);
- keys = g_key_file_get_keys(internalKeyFile, "Preferences", &length, NULL);
- if (keys != NULL)
- {
- for (ii = 0; keys[ii] != NULL; ii++)
- {
- value = g_key_file_get_value(prefsKeyFile, "Preferences", keys[ii], NULL);
- if (value != NULL)
- {
- ghb_settings_set_string(ud->settings, keys[ii], value);
- ghb_ui_update(ud, keys[ii], value);
- g_free(value);
- }
- else
- {
- value = g_key_file_get_value(internalKeyFile, "Preferences", keys[ii], NULL);
- if (value != NULL)
- {
- ghb_settings_set_string(ud->settings, keys[ii], value);
- ghb_ui_update(ud, keys[ii], value);
- g_free(value);
- }
- }
- }
- g_strfreev(keys);
- }
- gint bval = ghb_settings_get_int(ud->settings, "show_presets");
- ghb_ui_update_int(ud, "show_presets", bval);
- if (ghb_settings_get_bool(ud->settings, "hbfd_feature"))
- {
- GtkAction *action;
- bval = ghb_settings_get_int(ud->settings, "hbfd");
- ghb_ui_update_int(ud, "hbfd", bval);
- action = GHB_ACTION (ud->builder, "hbfd");
- gtk_action_set_visible(action, TRUE);
- }
- else
- {
- ghb_ui_update_int(ud, "hbfd", 0);
- }
- prefs_initializing = FALSE;
-}
-
-void
-ghb_presets_load(signal_user_data_t *ud)
-{
- const gchar *dir;
- gchar *config;
- GHashTable *settings = ud->settings;
-
- g_debug("ghb_presets_load()\n");
- customKeyFile = g_key_file_new();
- standardKeyFile = g_key_file_new();
- dir = g_get_user_config_dir();
- config = g_strdup_printf ("%s/ghb/custom_presets", dir);
- if (g_file_test(config, G_FILE_TEST_IS_REGULAR))
- {
- g_key_file_load_from_file( customKeyFile, config,
- G_KEY_FILE_KEEP_COMMENTS, NULL);
- }
- g_free(config);
- // Try current dir first. Makes testing prior to installation easier
- if (g_file_test("./standard_presets", G_FILE_TEST_IS_REGULAR))
- {
- g_key_file_load_from_file( standardKeyFile, "./standard_presets",
- G_KEY_FILE_KEEP_COMMENTS, NULL);
- }
- else
- {
- // Try users config dir
- config = g_strdup_printf ("%s/ghb/standard_presets", dir);
- if (g_file_test(config, G_FILE_TEST_IS_REGULAR))