/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
/*
 * gtk_main.c
 * Copyright (C) Steffen Pohle 2009 <steffen@gulpe.de>
 * 
 * main.c is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * main.c is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>

#include "map.h"
#include "gtk_port.h"
#include "memoryleak.h"
#include "routing.h"

int gtk_running = 1;

char dialog_filename[LEN_FILENAME];
char *dialog_getfilename (char *caption, char *filter, int save) {
	GtkWidget *dialog;
	
	if (save) dialog = gtk_file_chooser_dialog_new (_("Open GPSLog File"), GTK_WINDOW(main_wnd),
				      GTK_FILE_CHOOSER_ACTION_SAVE,
				      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				      GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
				      NULL);
	else  dialog = gtk_file_chooser_dialog_new (_("Open GPSLog File"), GTK_WINDOW(main_wnd),
				      GTK_FILE_CHOOSER_ACTION_OPEN,
				      GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
				      GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
				      NULL);

	if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) {
		char *filename;
		filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
		strncpy (dialog_filename, filename, LEN_FILENAME);
		g_free (filename);
		gtk_widget_destroy (dialog);
		return dialog_filename;
	}
	gtk_widget_destroy (dialog);
	return NULL;
};



int main (int argc, char *argv[]) {
    /* GtkWidget is the storage type for widgets */
    GtkWidget *window;
	
#ifdef ENABLE_NLS
	bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif

	app_init (argc, argv);
	gtk_set_locale ();
	gtk_init (&argc, &argv);
	
	window = main_wnd_create ();
	gtk_widget_show_all (window);
	gtk_main ();
	
	/* save configs */
	app_shutdown ();

	return 0;
};

