示例#1
0
文件: navit.c 项目: justinzane/navit
struct navit *
navit_new(const char *ui, const char *graphics, struct coord *center, enum projection pro, int zoom)
{
	struct navit *this_=g_new0(struct navit, 1);
	FILE *f;

	main_add_navit(this_);
	this_->vehicle_cbl=callback_list_new();

	f=popen("pidof /usr/bin/ipaq-sleep","r");
	if (f) {
		fscanf(f,"%d",&this_->pid);
		dbg(1,"ipaq_sleep pid=%d\n", this_->pid);
		pclose(f);
	}

	this_->bookmarks_hash=g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
	this_->cursor_flag=1;
	this_->tracking_flag=1;
	this_->trans=transform_new();
	transform_set_projection(this_->trans, pro);

	transform_setup(this_->trans, center, zoom, 0);
	this_->displaylist=graphics_displaylist_new();
	this_->gui=gui_new(this_, ui, 792, 547);
	if (! this_->gui) {
		g_warning("failed to create gui '%s'", ui);
		navit_destroy(this_);
		return NULL;
	}
	if (gui_has_main_loop(this_->gui)) {
		if (! main_loop_gui) {
			main_loop_gui=this_->gui;
		} else {
			g_warning("gui with main loop already active, ignoring this instance");
			navit_destroy(this_);
			return NULL;
		}
	}
	this_->menubar=gui_menubar_new(this_->gui);
	this_->toolbar=gui_toolbar_new(this_->gui);
	this_->statusbar=gui_statusbar_new(this_->gui);
	this_->gra=graphics_new(graphics);
	if (! this_->gra) {
		g_warning("failed to create graphics '%s'", graphics);
		navit_destroy(this_);
		return NULL;
	}
	graphics_register_resize_callback(this_->gra, navit_resize, this_);
	graphics_register_button_callback(this_->gra, navit_button, this_);
	if (gui_set_graphics(this_->gui, this_->gra)) {
		g_warning("failed to connect graphics '%s' to gui '%s'\n", graphics, ui);
		navit_destroy(this_);
		return NULL;
	}
	graphics_init(this_->gra);
	return this_;
}
示例#2
0
struct bookmarks *
bookmarks_new(struct attr *parent, struct attr **attrs, struct transformation *trans)
{
	struct bookmarks *this_;

	if (parent->type!=attr_navit)
	{
		return NULL;
	}

	dbg(0,"bb 001\n");

	this_ = g_new0(struct bookmarks,1);
	this_->attr_cbl=callback_list_new("bookmarks_new:this_->attr_cbl");
	this_->parent=parent;
	//this_->attrs=attr_list_dup(attrs);
	this_->trans=trans;


	return this_;

#if 0
	dbg(0,"bb 002\n");

	this_->bookmark_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/bookmark.txt", NULL);
	this_->working_file=g_strjoin(NULL, navit_get_user_data_directory(TRUE), "/bookmark.txt.tmp", NULL);

	dbg(0,"bb 003\n");

	this_->clipboard=g_new0(struct bookmark_item_priv,1);

	dbg(0,"bb 004\n");

	{
		//Load map now
		struct attr type={attr_type, {"textfile"}}, data={attr_data, {this_->bookmark_file}};
		struct attr *attrs[]={&type, &data, NULL};
		this_->bookmark=map_new(this_->parent, attrs);
		if (!this_->bookmark)
		{
			return NULL;
		}
		dbg(0,"bb 005\n");
		bookmarks_load_hash(this_);
	}

	dbg(0,"bb 006\n");

	return this_;
#endif
}
示例#3
0
/**
 * Creates a new graphics object
 * attr type required
 * @param <>
 * @returns <>
 * @author Martin Schaller (04/2008)
*/
struct graphics * graphics_new(struct attr *parent, struct attr **attrs)
{
	struct graphics *this_;
    	struct attr *type_attr;
	struct graphics_priv * (*graphicstype_new)(struct navit *nav, struct graphics_methods *meth, struct attr **attrs, struct callback_list *cbl);

        if (! (type_attr=attr_search(attrs, NULL, attr_type))) {
                return NULL;
        }

	graphicstype_new=plugin_get_graphics_type(type_attr->u.str);
	if (! graphicstype_new)
		return NULL;
	this_=g_new0(struct graphics, 1);
	this_->cbl=callback_list_new();
	this_->priv=(*graphicstype_new)(parent->u.navit, &this_->meth, attrs, this_->cbl);
	this_->attrs=attr_list_dup(attrs);
	return this_;
}
示例#4
0
struct vehicle *
vehicle_new(struct attr **attrs)
{
	struct vehicle *this_;
	struct attr *source;
	struct vehicle_priv *(*vehicletype_new) (struct vehicle_methods *
						 meth,
						 struct callback_list *
						 cbl,
						 struct attr ** attrs);
	char *type, *colon;

	dbg(1, "enter\n");
	source = attr_search(attrs, NULL, attr_source);
	if (!source) {
		dbg(0, "no source\n");
		return NULL;
	}

	type = g_strdup(source->u.str);
	colon = index(type, ':');
	if (colon)
		*colon = '\0';
	dbg(1, "source='%s' type='%s'\n", source->u.str, type);

	vehicletype_new = plugin_get_vehicle_type(type);
	if (!vehicletype_new) {
		dbg(0, "invalid type\n");
		return NULL;
	}
	this_ = g_new0(struct vehicle, 1);
	this_->cbl = callback_list_new();
	this_->priv = vehicletype_new(&this_->meth, this_->cbl, attrs);
	if (!this_->priv) {
		dbg(0, "vehicletype_new failed\n");
		callback_list_destroy(this_->cbl);
		g_free(this_);
		return NULL;
	}
	dbg(1, "leave\n");

	return this_;
}
示例#5
0
	g_free(config);
	exit(0);
}

static void
config_terminate(int sig)
{
	dbg(0,"terminating\n");
	config_destroy(config);
}

static void
config_new_int(void)
{
	config=g_new0(struct config, 1);
	config->cbl=callback_list_new();
#ifndef HAVE_API_WIN32_CE
	signal(SIGTERM, config_terminate);
#ifndef HAVE_API_WIN32
#ifndef __MINGW32__
	signal(SIGPIPE, SIG_IGN);
#endif /* __MINGW32__ */
#endif
#endif
}

int
config_get_attr(struct config *this_, enum attr_type type, struct attr *attr, struct attr_iter *iter)
{
	return attr_generic_get_attr(this_->attrs, NULL, type, attr, iter);
}
示例#6
0
struct vehicle *
vehicle_new(struct attr **attrs)
{
	struct vehicle *v;
	struct attr *name,*update,*follow,*color,*active,*source, *id;
	struct vehicle_priv *(*vehicletype_new) (struct vehicle_methods *
						 meth,
						 struct callback_list *
						 cbl,
						 struct attr ** attrs);
	char *type, *colon;

	dbg(1, "enter\n");
	source = attr_search(attrs, NULL, attr_source);
	if (!source) {
		dbg(0, "no source\n");
		return NULL;
	}

	type = g_strdup(source->u.str);
	colon = index(type, ':');
	if (colon)
		*colon = '\0';
	dbg(1, "source='%s' type='%s'\n", source->u.str, type);

	vehicletype_new = plugin_get_vehicle_type(type);
	if (!vehicletype_new) {
		dbg(0, "invalid type\n");
		return NULL;
	}
	v = g_new0(struct vehicle, 1);
	v->cbl = callback_list_new();
	v->priv = vehicletype_new(&v->meth, v->cbl, attrs);
	if (!v->priv) {
		dbg(0, "vehicletype_new failed\n");
		callback_list_destroy(v->cbl);
		g_free(v);
		return NULL;
	}
	v->update = 1;
	v->follow = 0;
	v->active = 0;
	if ((name=attr_search(attrs, NULL, attr_name)))
		v->name=g_strdup(name->u.str);
	else
		v->name=g_strdup("Noname");

	if ((id=attr_search(attrs, NULL, attr_vehicle_id)))
		v->id=id->u.num;
	if ((update=attr_search(attrs, NULL, attr_update)))
		v->update=update->u.num;
	if ((follow=attr_search(attrs, NULL, attr_follow)))
		v->follow=follow->u.num;
	if ((color=attr_search(attrs, NULL, attr_color))) 
		v->c=*(color->u.color);
	if ((active=attr_search(attrs, NULL, attr_active)) && active->u.num) {
		v->active = 1;
//		navit_set_vehicle(this_, v);
	}

	dbg(1, "leave\n");

	return v;
}
示例#7
0
/**************************************************************************
  The main loop for the UI.  This is called from main(), and when it
  exits the client will exit.
**************************************************************************/
void ui_main(int argc, char *argv[])
{
    SDL_Event __Net_User_Event;
    SDL_Event __GGZ_User_Event;
    SDL_Event __Anim_User_Event;
    SDL_Event __Info_User_Event;
    SDL_Event __Flush_User_Event;
    SDL_Event __pMap_Scroll_User_Event;

    parse_options(argc, argv);

    __Net_User_Event.type = SDL_USEREVENT;
    __Net_User_Event.user.code = NET;
    __Net_User_Event.user.data1 = NULL;
    __Net_User_Event.user.data2 = NULL;
    pNet_User_Event = &__Net_User_Event;

    __GGZ_User_Event.type = SDL_USEREVENT;
    __GGZ_User_Event.user.code = GGZ;
    __GGZ_User_Event.user.data1 = NULL;
    __GGZ_User_Event.user.data2 = NULL;
    pGGZ_User_Event = &__GGZ_User_Event;

    __Anim_User_Event.type = SDL_USEREVENT;
    __Anim_User_Event.user.code = EVENT_ERROR;
    __Anim_User_Event.user.data1 = NULL;
    __Anim_User_Event.user.data2 = NULL;
    pAnim_User_Event = &__Anim_User_Event;

    __Info_User_Event.type = SDL_USEREVENT;
    __Info_User_Event.user.code = SHOW_WIDGET_INFO_LABBEL;
    __Info_User_Event.user.data1 = NULL;
    __Info_User_Event.user.data2 = NULL;
    pInfo_User_Event = &__Info_User_Event;

    __Flush_User_Event.type = SDL_USEREVENT;
    __Flush_User_Event.user.code = FLUSH;
    __Flush_User_Event.user.data1 = NULL;
    __Flush_User_Event.user.data2 = NULL;
    pFlush_User_Event = &__Flush_User_Event;

    __pMap_Scroll_User_Event.type = SDL_USEREVENT;
    __pMap_Scroll_User_Event.user.code = MAP_SCROLL;
    __pMap_Scroll_User_Event.user.data1 = NULL;
    __pMap_Scroll_User_Event.user.data2 = NULL;
    pMap_Scroll_User_Event = &__pMap_Scroll_User_Event;

    is_unit_move_blocked = FALSE;

    SDL_Client_Flags |= (CF_DRAW_PLAYERS_NEUTRAL_STATUS|
                         CF_DRAW_PLAYERS_WAR_STATUS|
                         CF_DRAW_PLAYERS_CEASEFIRE_STATUS|
                         CF_DRAW_PLAYERS_PEACE_STATUS|
                         CF_DRAW_PLAYERS_ALLIANCE_STATUS);

    tileset_init(tileset);
    tileset_load_tiles(tileset);
    tileset_use_prefered_theme(tileset);

    load_cursors();

    callbacks = callback_list_new();

    diplomacy_dialog_init();
    intel_dialog_init();

    clear_double_messages_call();

    setup_auxiliary_tech_icons();

    if (gui_sdl_fullscreen) {
#ifdef SMALL_SCREEN
#ifdef UNDER_CE
        /* set 320x240 fullscreen */
        set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height,
                       SDL_SWSURFACE | SDL_ANYFORMAT | SDL_FULLSCREEN);
#else  /* UNDER_CE */
        /* small screen on desktop -> don't set 320x240 fullscreen mode */
        set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height,
                       SDL_SWSURFACE | SDL_ANYFORMAT);
#endif /* UNDER_CE */
#else  /* SMALL_SCREEN */
        set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height,
                       SDL_SWSURFACE | SDL_ANYFORMAT | SDL_FULLSCREEN);
#endif /* SMALL_SCREEN */

    } else {

#ifdef SMALL_SCREEN
#ifdef UNDER_CE
        set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height,
                       SDL_SWSURFACE | SDL_ANYFORMAT);
#else  /* UNDER_CE */
        set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height,
                       SDL_SWSURFACE | SDL_ANYFORMAT);
#endif /* UNDER_CE */
#else  /* SMALL_SCREEN */
        set_video_mode(gui_sdl_screen.width, gui_sdl_screen.height,
                       SDL_SWSURFACE | SDL_ANYFORMAT);
#endif /* SMALL_SCREEN */

#if 0
        /*
         * call this for other that X enviroments - currently not supported.
         */
        center_main_window_on_screen();
#endif /* 0 */
    }

    /* SDL_WM_SetCaption(_("SDL Client for Freeciv"), _("Freeciv")); */

    /* this need correct Main.screen size */
    init_mapcanvas_and_overview();

    set_client_state(C_S_DISCONNECTED);

    /* Main game loop */
    gui_event_loop(NULL, NULL, main_key_down_handler, main_key_up_handler,
                   main_mouse_button_down_handler, main_mouse_button_up_handler,
                   main_mouse_motion_handler);

}
示例#8
0
static struct vehicle_priv *
vehicle_wince_new(struct vehicle_methods
		      *meth, struct callback_list
		      *cbl, struct attr **attrs)
{
	struct vehicle_priv *ret;
	struct attr *source;
	struct attr *time;
	struct attr *on_eof;
	struct attr *baudrate;
	struct attr *checksum_ignore;
	struct attr *handle_bluetooth;
	char *cp;

	dbg(1, "enter\n");
	source = attr_search(attrs, NULL, attr_source);
	ret = g_new0(struct vehicle_priv, 1);
	ret->fd = -1;
	ret->cbl = cbl;
	
	ret->file_type = file_type_device;
	cp = strchr(source->u.str,':');
	if (cp)
	{
	    if ( strncmp(source->u.str, "file", 4) == 0 )
	        ret->file_type = file_type_file;
		cp++;
	}
	else
		cp = source->u.str;
	ret->source = g_strdup(cp);
	ret->buffer = g_malloc(buffer_size);
	ret->time=1000;
	ret->baudrate=0;	// do not change the rate if not configured

	time = attr_search(attrs, NULL, attr_time);
	if (time)
		ret->time=time->u.num;
	baudrate = attr_search(attrs, NULL, attr_baudrate);
	if (baudrate) {
		ret->baudrate = baudrate->u.num;
	}
	checksum_ignore = attr_search(attrs, NULL, attr_checksum_ignore);
	if (checksum_ignore)
		ret->checksum_ignore=checksum_ignore->u.num;
	ret->attrs = attrs;
	on_eof = attr_search(attrs, NULL, attr_on_eof);
	if (on_eof && !strcasecmp(on_eof->u.str, "stop"))
		ret->on_eof=1;
	if (on_eof && !strcasecmp(on_eof->u.str, "exit"))
		ret->on_eof=2;
	dbg(0,"on_eof=%d\n", ret->on_eof);
	*meth = vehicle_wince_methods;
	ret->priv_cbl = callback_list_new();
	callback_list_add(ret->priv_cbl, callback_new_1(callback_cast(vehicle_wince_io), ret));
	ret->sat_item.type=type_position_sat;
	ret->sat_item.id_hi=ret->sat_item.id_lo=0;
	ret->sat_item.priv_data=ret;
	ret->sat_item.meth=&vehicle_wince_sat_methods;

    ret->read_buffer = g_malloc(buffer_size);

	handle_bluetooth = attr_search(attrs, NULL, attr_bluetooth);
	if ( handle_bluetooth && handle_bluetooth->u.num == 1 )
		initBth(ret);

	if (vehicle_wince_open(ret)) {
		vehicle_wince_enable_watch(ret);
		return ret;
	}
	dbg(0, "Failed to open '%s'\n", ret->source);
	vehicle_wince_destroy(ret);
	return NULL;
}