
#include "osmroute.h"
#include "favorites.h"
#include "routing.h"
#include "gui.h"

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

struct appdata app;

int app_init (int argc, char **argv) {
	app.status = APPSTATUS_nothing;

	config_init ();
	d_printf ("************ cfg.last_scale:%f", cfg.last_scale);
	map_init ();
	d_printf ("************ cfg.last_scale:%f", cfg.last_scale);

#ifdef SPOSMROUTE
	draw_init ();
	d_printf ("************ cfg.last_scale:%f", cfg.last_scale);
	fav_load (fav_getfilename ());
	d_printf ("************ cfg.last_scale:%f", cfg.last_scale);
#endif
	return 0;
};


int app_shutdown () {
#ifdef SPOSMROUTE
	cfg.last_lon = view_lon;
	cfg.last_lat = view_lat;
	cfg.last_scale = view_scale;
	gps_stop ();
	route_stop ();
#endif

	config_save ();
	map_save_all ();
	
	return 0;
};


/******************************************************************************
 * update stausbar 
 */
void app_status (char *text, int progress) {
	static char oldtext[255];

	if (text) strncpy (app.statusline_text, text, 255);
	else strncpy (app.statusline_text, oldtext, 255);
	app.statusline_progress = progress;

#ifdef SPOSMROUTE
	if (currentwin) currentwin->screen_changed = 1;
	draw ();
#endif
};
