Changeset - b2fd4a456335
[Not reviewed]
0 4 0
HanzZ - 14 years ago 2011-08-16 21:51:19
hanzz.k@gmail.com
parse unregistered config options and working [purple] options parsing
4 files changed with 27 insertions and 1 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/main.cpp
Show inline comments
 
@@ -231,6 +231,15 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
			purple_account_set_bool(account, "custom_smileys", FALSE);
 
			purple_account_set_bool(account, "direct_connect", FALSE);
 

	
 
			for (std::map<std::string,std::string>::const_iterator it = config->getUnregistered().begin();
 
				it != config->getUnregistered().end(); it++) {
 
				if ((*it).first.find("purple.") == 0) {
 
					std::string key = (*it).first.substr((*it).first.find(".") + 1);
 
					LOG4CXX_INFO(logger, "Setting account string '" << key << "'='" << (*it).second << "'");
 
					purple_account_set_string(account, key.c_str(), (*it).second.c_str());
 
				}
 
			}
 

	
 
			purple_account_set_privacy_type(account, PURPLE_PRIVACY_DENY_USERS);
 

	
 
			const PurpleStatusType *status_type = purple_account_get_status_type_with_primitive(account, PURPLE_STATUS_AVAILABLE);
include/transport/config.h
Show inline comments
 
@@ -82,11 +82,16 @@ class Config {
 
		/// Returns path to config file from which data were loaded.
 
		const std::string &getConfigFile() { return m_file; }
 

	
 
		const std::map<std::string, std::string> &getUnregistered() {
 
			return m_unregistered;
 
		}
 

	
 
		/// This signal is emitted when config is loaded/reloaded.
 
		boost::signal<void ()> onConfigReloaded;
 
	
 
	private:
 
		Variables m_variables;
 
		std::map<std::string, std::string> m_unregistered;
 
		std::string m_file;
 
};
 

	
spectrum/src/sample.cfg
Show inline comments
 
@@ -20,6 +20,9 @@ protocol=any
 

	
 
[backend]
 
default_avatar=catmelonhead.jpg
 
[purple]
 
test=test1
 
test2=test3
 

	
 
[logging]
 
#config=logging.cfg # log4cxx/log4j logging configuration file
src/config.cpp
Show inline comments
 
@@ -26,6 +26,7 @@ using namespace boost::program_options;
 
namespace Transport {
 

	
 
bool Config::load(const std::string &configfile, boost::program_options::options_description &opts) {
 
	m_unregistered.clear();
 
	std::ifstream ifs(configfile.c_str());
 
	if (!ifs.is_open())
 
		return false;
 
@@ -71,7 +72,15 @@ bool Config::load(const std::string &configfile, boost::program_options::options
 
		("backend.avatars_directory", value<std::string>()->default_value(""), "Path to directory with avatars")
 
	;
 

	
 
	store(parse_config_file(ifs, opts), m_variables);
 
	parsed_options parsed = parse_config_file(ifs, opts, true);
 

	
 
	BOOST_FOREACH(option opt, parsed.options) {
 
		if (opt.unregistered) {
 
			m_unregistered[opt.string_key] = opt.value[0];
 
		}
 
	}
 

	
 
	store(parsed, m_variables);
 
	notify(m_variables);
 

	
 
	m_file = configfile;
0 comments (0 inline, 0 general)