static void
thunar_uca_chooser_save (ThunarUcaChooser *uca_chooser,
                         ThunarUcaModel   *uca_model)
{
  GtkWidget *dialog;
  GError    *error = NULL;

  g_return_if_fail (THUNAR_UCA_IS_CHOOSER (uca_chooser));
  g_return_if_fail (THUNAR_UCA_IS_MODEL (uca_model));

  /* sync the model to persistent storage */
  if (!thunar_uca_model_save (uca_model, &error))
    {
      dialog = gtk_message_dialog_new (GTK_WINDOW (uca_chooser),
                                       GTK_DIALOG_DESTROY_WITH_PARENT
                                       | GTK_DIALOG_MODAL,
                                       GTK_MESSAGE_ERROR,
                                       GTK_BUTTONS_CLOSE,
                                       _("Failed to save actions to disk."));
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", error->message);
      gtk_dialog_run (GTK_DIALOG (dialog));
      gtk_widget_destroy (dialog);
      g_error_free (error);
    }
}
/**
 * thunar_uca_editor_load:
 * @uca_editor  : a #ThunarUcaEditor.
 * @uca_model   : a #ThunarUcaModel.
 * @iter        : a #GtkTreeIter.
 *
 * Loads @uca_editor with the data from @uca_model
 * at the specified @iter.
 **/
void
thunar_uca_editor_load (ThunarUcaEditor *uca_editor,
                        ThunarUcaModel  *uca_model,
                        GtkTreeIter     *iter)
{
    ThunarUcaTypes types;
    gchar         *description;
    gchar         *patterns;
    gchar         *command;
    gchar         *icon_name;
    gchar         *name;
    gboolean       startup_notify;

    g_return_if_fail (THUNAR_UCA_IS_EDITOR (uca_editor));
    g_return_if_fail (THUNAR_UCA_IS_MODEL (uca_model));
    g_return_if_fail (iter != NULL);

    /* determine the current values from the model */
    gtk_tree_model_get (GTK_TREE_MODEL (uca_model), iter,
                        THUNAR_UCA_MODEL_COLUMN_DESCRIPTION, &description,
                        THUNAR_UCA_MODEL_COLUMN_PATTERNS, &patterns,
                        THUNAR_UCA_MODEL_COLUMN_COMMAND, &command,
                        THUNAR_UCA_MODEL_COLUMN_TYPES, &types,
                        THUNAR_UCA_MODEL_COLUMN_ICON_NAME, &icon_name,
                        THUNAR_UCA_MODEL_COLUMN_NAME, &name,
                        THUNAR_UCA_MODEL_COLUMN_STARTUP_NOTIFY, &startup_notify,
                        -1);

    /* setup the new selection */
    thunar_uca_editor_set_types (uca_editor, types);

    /* setup the new icon */
    thunar_uca_editor_set_icon_name (uca_editor, icon_name);

    /* apply the new values */
    gtk_entry_set_text (GTK_ENTRY (uca_editor->description_entry), (description != NULL) ? description : "");
    gtk_entry_set_text (GTK_ENTRY (uca_editor->patterns_entry), (patterns != NULL) ? patterns : "");
    gtk_entry_set_text (GTK_ENTRY (uca_editor->command_entry), (command != NULL) ? command : "");
    gtk_entry_set_text (GTK_ENTRY (uca_editor->name_entry), (name != NULL) ? name : "");
    gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (uca_editor->sn_button), startup_notify);

    /* cleanup */
    g_free (description);
    g_free (patterns);
    g_free (command);
    g_free (icon_name);
    g_free (name);
}
/**
 * thunar_uca_editor_save:
 * @uca_editor : a #ThunarUcaEditor.
 * @uca_model  : a #ThunarUcaModel.
 * @iter       : a #GtkTreeIter.
 *
 * Stores the current values from the @uca_editor in
 * the @uca_model at the item specified by @iter.
 **/
void
thunar_uca_editor_save (ThunarUcaEditor *uca_editor,
                        ThunarUcaModel  *uca_model,
                        GtkTreeIter     *iter)
{
    g_return_if_fail (THUNAR_UCA_IS_EDITOR (uca_editor));
    g_return_if_fail (THUNAR_UCA_IS_MODEL (uca_model));
    g_return_if_fail (iter != NULL);

    thunar_uca_model_update (uca_model, iter,
                             gtk_entry_get_text (GTK_ENTRY (uca_editor->name_entry)),
                             NULL, /* don't touch the unique id */
                             gtk_entry_get_text (GTK_ENTRY (uca_editor->description_entry)),
                             thunar_uca_editor_get_icon_name (uca_editor),
                             gtk_entry_get_text (GTK_ENTRY (uca_editor->command_entry)),
                             gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (uca_editor->sn_button)),
                             gtk_entry_get_text (GTK_ENTRY (uca_editor->patterns_entry)),
                             thunar_uca_editor_get_types (uca_editor));
}