/* clearLocale.c
 * Called by gddcalc when the user presses the "clear" button on
 * the locale display. Clears the entry boxes of the locale display
 * and deletes any file named "locale.txt" that exists.
 */

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gddcalc.h"

void clearLocale() {

	size_t lth = 64;
	char *bfr = malloc(lth);
	FILE *fp;

/* First, clear out the locale display */

	haveprefs = 0;
	strcpy(bfr, "\0");
	gtk_entry_set_text (GTK_ENTRY (locale_entry_lat), (gchar*) bfr);
	gtk_entry_set_text (GTK_ENTRY (locale_entry_lon), (gchar*) bfr);
	gtk_entry_set_text (GTK_ENTRY (locale_entry_elev), (gchar*) bfr);
	gtk_entry_set_text (GTK_ENTRY (locale_entry_aspect), (gchar*) bfr);
	gtk_entry_set_text (GTK_ENTRY (locale_entry_tilt), (gchar*) bfr);
	free(bfr);

/* Then remove locale.txt, if it exists */

	fp = fopen("locale.txt", "r");
	if (fp == NULL) return;
	unlink("locale.txt");
	return;
}
