예제 #1
0
bool
Settings::load_from_file(const synfig::String& filename)
{
	std::ifstream file(filename.c_str());
	if(!file)
		return false;
	while(file)
	{
		std::string line;
		getline(file,line);
		if(!line.empty() && ((line[0]>='a' && line[0]<='z')||(line[0]>='A' && line[0]<='Z')))
		{
			std::string::iterator equal(find(line.begin(),line.end(),'='));
			if(equal==line.end())
				continue;
			std::string key(line.begin(),equal);
			std::string value(equal+1,line.end());

			//synfig::info("Settings::load_from_file(): Trying Key \"%s\" with a value of \"%s\".",key.c_str(),value.c_str());
			try{
			if(!set_value(key,value))
				synfig::warning("Settings::load_from_file(): Key \"%s\" with a value of \"%s\" was rejected.",key.c_str(),value.c_str());
			}
			catch(...)
			{
				synfig::error("Settings::load_from_file(): Attempt to set key \"%s\" with a value of \"%s\" has thrown an exception.",key.c_str(),value.c_str());
				throw;
			}
		}
	}
	return true;
}
예제 #2
0
Distance::System // (static)
Distance::ident_system(const synfig::String& x)
{
	synfig::String str;

	// Make it all upper case, and remove white space
	for(unsigned int i=0;i<x.size();i++)if(x[i]!=' ' && x[i]!='\t')str+=toupper(x[i]);

	// If it is plural, make it singular
	if(str[str.size()-1]=='S')
		str=synfig::String(str.begin(),str.end()-1);

	if(str.empty() || str=="U" || str=="UNIT")
		return SYSTEM_UNITS;
	if(str=="PX" || str=="PIXEL")
		return SYSTEM_PIXELS;
	if(str=="PT" || str=="POINT")
		return SYSTEM_POINTS;
	if(str=="IN" || str=="\"" || str=="INCHE" || str=="INCH")
		return SYSTEM_INCHES;
	if(str=="M" || str=="METER")
		return SYSTEM_METERS;
	if(str=="CM" || str=="CENTIMETER")
		return SYSTEM_CENTIMETERS;
	if(str=="MM" || str=="MILLIMETER")
		return SYSTEM_MILLIMETERS;

	synfig::warning("Distance::ident_system(): Unknown distance system \"%s\"",x.c_str());

	return SYSTEM_UNITS;
}
예제 #3
0
bool
Settings::save_to_file(const synfig::String& filename)const
{
	synfig::String tmp_filename(filename+".TMP");

	try
	{
		std::ofstream file(tmp_filename.c_str());

		if(!file)return false;

		KeyList key_list(get_key_list());

		// Save the keys
		{
			KeyList::const_iterator iter;
			for(iter=key_list.begin();iter!=key_list.end();++iter)
			{
				if(!file)return false;
				String ret = get_value(*iter);
				if (ret != String()) file<<*iter<<'='<<(ret == "none" ? "normal" : ret)<<endl;
			}
		}

		if(!file)
			return false;
	}catch(...) { return false; }

#ifdef _WIN32
	char old_file[80]="sif.XXXXXXXX";
	mktemp(old_file);
	rename(filename.c_str(),old_file);
	if(rename(tmp_filename.c_str(),filename.c_str())!=0)
	{
		rename(old_file,tmp_filename.c_str());
		return false;
	}
	remove(old_file);
#else
	if(rename(tmp_filename.c_str(),filename.c_str())!=0)
		return false;
#endif

	return true;
}
예제 #4
0
void
Toolbox::change_state(const synfig::String& statename)
{
	etl::handle<studio::CanvasView> canvas_view(studio::App::get_selected_canvas_view());
	if(canvas_view)
	{
		if(statename==canvas_view->get_smach().get_state_name())
		{
			return;
		}

		if(state_button_map.count(statename))
		{
			state_button_map[statename]->clicked();
		}
		else
		{
			synfig::error("Unknown state \"%s\"",statename.c_str());
		}
	}
}
bool
DialogSettings::set_value(const synfig::String& key,const synfig::String& value)
{
	int screen_w(Gdk::screen_width());
	int screen_h(Gdk::screen_height());

	if(value.empty())
		return false;

	if(key=="pos")
	{
		int x,y;
		if(!strscanf(value,"%d %d",&x, &y))
			return false;

		if (x > screen_w) x = screen_w - 150; if (x < 0) x = 0;
		if (y > screen_h) y = screen_h - 150; if (y < 0) y = 0;

		window->move(x,y);
		return true;
	}
	if(key=="size")
	{
		int x,y;
		if(!strscanf(value,"%d %d",&x, &y))
			return false;

		if (x > screen_w) x = 150; if (x < 0) x = 0;
		if (y > screen_h) y = 150; if (y < 0) y = 0;

		window->set_default_size(x,y);
		return true;
	}
	if(key=="x")
	{
		int x,y; window->get_position(x,y);
		x=atoi(value.c_str());
		window->move(x,y);
		return true;
	}
	if(key=="y")
	{
		int x,y; window->get_position(x,y);
		y=atoi(value.c_str());
		window->move(x,y);
		return true;
	}
	if(key=="w")
	{
		int x,y; window->get_size(x,y);
		x=atoi(value.c_str());
		window->set_default_size(x,y);
		return true;
	}
	if(key=="h")
	{
		int x,y; window->get_size(x,y);
		y=atoi(value.c_str());
		window->set_default_size(x,y);
		return true;
	}
	if(key=="visible")
	{
		if(value=="0")
			window->hide();
		else
			window->present();
		return true;
	}

	return synfigapp::Settings::set_value(key,value);
}