+/*******************************************************************************
+ * All configuration subsystem code is below
+ ******************************************************************************/
+
+/**
+ * Lookup a setting in the config file for this TildaTerminal.
+ *
+ * The returned string MUST be g_strdup()'d if you want to actually use
+ * it as a value. It is owned by the config system. You MUST NOT g_free() it.
+ */
+static gchar *
+tilda_terminal_lookup_from_config (TildaTerminal *self, const gchar key[])
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_TERMINAL(self));
+ debug_assert (key != NULL);
+
+ GError *error = NULL;
+ gchar *group_name;
+ gpointer value;
+
+ /* Do the bottom-most lookup */
+ group_name = g_strdup_printf ("Window%d/Terminal%d",
+ TILDA_WINDOW(self->parent_window)->number,
+ self->number);
+ value = g_key_file_get_string (config_userprefs, group_name, key, &error);
+ g_free (group_name);
+
+ if (!error)
+ return value;
+ else
+ g_clear_error (&error);
+
+ /* Do the next highest lookup */
+ group_name = g_strdup_printf ("Window%d",
+ TILDA_WINDOW(self->parent_window)->number);
+ value = g_key_file_get_string (config_userprefs, group_name, key, &error);
+ g_free (group_name);
+
+ if (!error)
+ return value;
+ else
+ g_clear_error (&error);
+
+ /* Do the global lookup */
+ value = g_key_file_get_string (config_userprefs, "Global", key, &error);
+
+ if (!error)
+ return value;
+ else
+ g_clear_error (&error);
+
+ /* Look in the defaults */
+ if (!g_hash_table_lookup_extended (config_defaults, key, NULL, &value))
+ {
+ /* If this happened, the developers forgot to set the default for
+ * a key they added. Please email them. */
+ g_critical ("Error: unable to find the default for key=%s\n", key);
+ exit (1);
+ }
+
+ /* Return the default key */
+ return value;
+}
+
+/**
+ * Set one of TildaTerminal's integer properties from the config file or defaults.
+ */
+static void
+tilda_terminal_config_int_property (TildaTerminal *self, const gchar *property)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_TERMINAL(self));
+ debug_assert (property != NULL);
+
+ gint config_value;
+ gchar *config_value_raw;
+
+ config_value_raw = tilda_terminal_lookup_from_config (self, property);
+ config_value = atoi (config_value_raw);
+ g_object_set (G_OBJECT(self), property, config_value, NULL);
+}
+
+static void
+tilda_terminal_config_enum_property (TildaTerminal *self, const gchar *property)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_TERMINAL(self));
+ debug_assert (property != NULL);
+
+ gint config_value;
+ gchar *config_value_raw;
+
+ /* Copy, then strip spaces off of the string from the config */
+ config_value_raw = g_strstrip (g_strdup (tilda_terminal_lookup_from_config (self, property)));
+
+begin_parsing:
+
+ /* Just try all of the possible enums */
+ if (g_ascii_strcasecmp (config_value_raw, "LEFT") == 0)
+ config_value = LEFT;
+ else if (g_ascii_strcasecmp (config_value_raw, "RIGHT") == 0)
+ config_value = RIGHT;
+ else if (g_ascii_strcasecmp (config_value_raw, "HOLD-OPEN") == 0)
+ config_value = HOLD_OPEN;
+ else if (g_ascii_strcasecmp (config_value_raw, "RESTART-COMMAND") == 0)
+ config_value = RESTART_COMMAND;
+ else if (g_ascii_strcasecmp (config_value_raw, "EXIT") == 0)
+ config_value = EXIT;
+ else if (g_ascii_strcasecmp (config_value_raw, "VTE-ERASE-AUTO") == 0)
+ config_value = VTE_ERASE_AUTO;
+ else if (g_ascii_strcasecmp (config_value_raw, "VTE-ERASE-ASCII-BACKSPACE") == 0)
+ config_value = VTE_ERASE_ASCII_BACKSPACE;
+ else if (g_ascii_strcasecmp (config_value_raw, "VTE-ERASE-ASCII-DELETE") == 0)
+ config_value = VTE_ERASE_ASCII_DELETE;
+ else if (g_ascii_strcasecmp (config_value_raw, "VTE-ERASE-DELETE-SEQUENCE") == 0)
+ config_value = VTE_ERASE_DELETE_SEQUENCE;
+ else if (g_ascii_strcasecmp (config_value_raw, "NOT-DISPLAYED") == 0)
+ config_value = NOT_DISPLAYED;
+ else if (g_ascii_strcasecmp (config_value_raw, "AFTER-INITIAL") == 0)
+ config_value = AFTER_INITIAL;
+ else if (g_ascii_strcasecmp (config_value_raw, "BEFORE-INITIAL") == 0)
+ config_value = BEFORE_INITIAL;
+ else if (g_ascii_strcasecmp (config_value_raw, "REPLACE-INITIAL") == 0)
+ config_value = REPLACE_INITIAL;
+ else
+ {
+ g_critical ("Unable to parse: '%s' as an enum\n", config_value_raw);
+
+ /* Use the default -- which I sure hope is valid (famous last words) */
+ config_value_raw = g_hash_table_lookup (config_defaults, property);
+ goto begin_parsing;
+ }
+
+ /* Free the value from the config system */
+ g_free (config_value_raw);
+
+ g_object_set (G_OBJECT(self), property, config_value, NULL);
+}
+
+static void
+tilda_terminal_config_string_property (TildaTerminal *self, const gchar *property)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_TERMINAL(self));
+ debug_assert (property != NULL);
+
+ gchar *config_value_raw;
+
+ config_value_raw = tilda_terminal_lookup_from_config (self, property);
+
+ /* The property system g_strdup()s strings for us! */
+ g_object_set (G_OBJECT(self), property, config_value_raw, NULL);
+}
+
+static void
+tilda_terminal_config_boolean_property (TildaTerminal *self, const gchar *property)
+{
+ debug_enter ();
+ debug_assert (TILDA_IS_TERMINAL(self));
+ debug_assert (property != NULL);
+
+ gboolean config_value;
+ gchar *config_value_raw;
+
+ config_value_raw = tilda_terminal_lookup_from_config (self, property);
+
+begin_parsing:
+
+ if (g_ascii_strcasecmp (config_value_raw, "true") == 0)
+ config_value = TRUE;
+ else if (g_ascii_strcasecmp (config_value_raw, "false") == 0)
+ config_value = FALSE;
+ else
+ {
+ g_critical ("Unable to parse: '%s' as a boolean\n", config_value_raw);
+
+ /* Use the default -- which I sure hope is valid (famous last words) */
+ config_value_raw = g_hash_table_lookup (config_defaults, property);
+ goto begin_parsing;
+ }
+
+ g_object_set (G_OBJECT(self), property, config_value, NULL);
+}
+
+