Changeset - 64a0a5d6b5cf
[Not reviewed]
0 1 0
HanzZ - 14 years ago 2011-09-16 13:02:40
hanzz.k@gmail.com
support setting int/bool in [purple] section
1 file changed with 39 insertions and 3 deletions:
0 comments (0 inline, 0 general)
backends/libpurple/main.cpp
Show inline comments
 
@@ -207,61 +207,97 @@ class SpectrumNetworkPlugin : public NetworkPlugin {
 
			}
 

	
 
			m_sessions[user] = account;
 
			m_accounts[account] = user;
 

	
 
			// Default avatar
 
			char* contents;
 
			gsize length;
 
			gboolean ret = false;
 
			if (!CONFIG_STRING(config, "backend.avatars_directory").empty()) {
 
				std::string f = CONFIG_STRING(config, "backend.avatars_directory") + "/" + legacyName;
 
				ret = g_file_get_contents (f.c_str(), &contents, &length, NULL);
 
			}
 

	
 
			if (!CONFIG_STRING(config, "backend.default_avatar").empty() && !ret) {
 
				ret = g_file_get_contents (CONFIG_STRING(config, "backend.default_avatar").c_str(),
 
											&contents, &length, NULL);
 
			}
 

	
 
			if (ret) {
 
				purple_buddy_icons_set_account_icon(account, (guchar *) contents, length);
 
			}
 

	
 
			purple_account_set_password(account, password.c_str());
 
			purple_account_set_enabled(account, "spectrum", TRUE);
 
			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());
 

	
 
					PurplePlugin *plugin = purple_find_prpl(protocol.c_str());
 
					PurplePluginProtocolInfo *prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(plugin);
 
					bool found = false;
 
					for (GList *l = prpl_info->protocol_options; l != NULL; l = l->next) {
 
						PurpleAccountOption *option = (PurpleAccountOption *) l->data;
 
						PurplePrefType type = purple_account_option_get_type(option);
 
						std::string key2(purple_account_option_get_setting(option));
 
						std::cout << key << " " << key2 << " " << (*it).second << "\n";
 
						if (key != key2)
 
							continue;
 
						
 
						found = true;
 
						switch (type) {
 
							case PURPLE_PREF_BOOLEAN:
 
								purple_account_set_bool(account, key.c_str(), boost::lexical_cast<bool>((*it).second));
 
								break;
 

	
 
							case PURPLE_PREF_INT:
 
								std::cout << "setting int\n";
 
								purple_account_set_int(account, key.c_str(), boost::lexical_cast<int>((*it).second));
 
								break;
 

	
 
							case PURPLE_PREF_STRING:
 
							case PURPLE_PREF_STRING_LIST:
 
								purple_account_set_string(account, key.c_str(), (*it).second.c_str());
 
								break;
 
							default:
 
								continue;
 
						}
 
						break;
 
					}
 

	
 
					if (!found) {
 
						std::cout << "setting string\n";
 
						purple_account_set_string(account, key.c_str(), (*it).second.c_str());
 
					}
 
				}
 
			}
 

	
 
			purple_account_set_enabled(account, "spectrum", TRUE);
 

	
 
			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);
 
			if (status_type != NULL) {
 
				purple_account_set_status(account, purple_status_type_get_id(status_type), TRUE, NULL);
 
			}
 
		}
 

	
 
		void handleLogoutRequest(const std::string &user, const std::string &legacyName) {
 
			PurpleAccount *account = m_sessions[user];
 
			if (account) {
 
// 				VALGRIND_DO_LEAK_CHECK;
 
				m_sessions.erase(user);
 
				purple_account_disconnect(account);
 
				purple_account_set_enabled(account, "spectrum", FALSE);
 

	
 
				// Remove conversations.
 
				// This has to be called before m_account->ui_data = NULL;, because it uses
 
				// ui_data to call SpectrumMessageHandler::purpleConversationDestroyed() callback.
 
				GList *iter;
 
				for (iter = purple_get_conversations(); iter; ) {
 
					PurpleConversation *conv = (PurpleConversation*) iter->data;
 
					iter = iter->next;
 
					if (purple_conversation_get_account(conv) == account)
0 comments (0 inline, 0 general)