示例#1
0
	void read_notify_list(model& aModel, std::function<bool()> aErrorFunction)
	{
		notify& theNotifyList = aModel.notify_list();

		neolib::xml xmlNotifyList(true);
		std::ifstream input((aModel.root_path() + "notify_list.xml").c_str());
		xmlNotifyList.read(input);

		if (xmlNotifyList.error() && aErrorFunction && aErrorFunction())
		{
			theNotifyList.entries().clear();
			write_notify_list(aModel);
			return;
		}

		theNotifyList.loading(true);

		for (neolib::xml::element::const_iterator i = xmlNotifyList.root().begin(); i != xmlNotifyList.root().end(); ++i)
		{
			if (i->name() == "entry")
			{
				notify_entry_ptr e(new notify_entry);
				for (neolib::xml::element::const_iterator j = i->begin(); j != i->end(); ++j)
				{
					if (j->name() == "user")
						e->user() = user(j->attribute_value("value"), casemapping::rfc1459, false, true);
					if (j->name() == "server_network" || j->name() == "server_group")
						e->server().first = j->attribute_value("value");
					if (j->name() == "server_name")
						e->server().second = j->attribute_value("value");
					if (j->name() == "channel")
						e->channel() = j->attribute_value("value");
					if (j->name() == "action")
						e->action() = static_cast<notify_entry::action_e>(neolib::string_to_integer<char>(j->attribute_value("value")));
					if (j->name() == "event")
						e->event() = static_cast<notify_entry::event_e>(neolib::string_to_integer<char>(j->attribute_value("value")));
					if (j->name() == "data")
						e->data() = j->attribute_value("value");
				}
				if (e->user().nick_name().empty())
					e->user().nick_name() = "*";
				if (e->channel().empty())
					e->channel() = "*";
				theNotifyList.entries().push_back(e);
			}
		}

		theNotifyList.loading(false);
	}
示例#2
0
	void write_notify_list(const model& aModel)
	{
		const notify& theNotifyList = aModel.notify_list();

		neolib::xml xmlNotifyList(true);

		xmlNotifyList.root().name() = "notify_list";

		for (notify::container_type::const_iterator i = theNotifyList.entries().begin(); i != theNotifyList.entries().end(); ++i)
		{
			const notify_entry& entry = **i;
			neolib::xml::element& xmlEntry = xmlNotifyList.append(xmlNotifyList.root(), "entry");
			xmlNotifyList.append(xmlEntry, "user").set_attribute("value", entry.user().msgto_form());
			xmlNotifyList.append(xmlEntry, "server_network").set_attribute("value", entry.server().first);
			xmlNotifyList.append(xmlEntry, "server_name").set_attribute("value", entry.server().second);
			xmlNotifyList.append(xmlEntry, "channel").set_attribute("value", entry.channel());
			xmlNotifyList.append(xmlEntry, "action").set_attribute("value", neolib::integer_to_string<char>(entry.action()));
			xmlNotifyList.append(xmlEntry, "event").set_attribute("value", neolib::integer_to_string<char>(entry.event()));
			xmlNotifyList.append(xmlEntry, "data").set_attribute("value", entry.data());
		}

		std::ofstream output((aModel.root_path() + "notify_list.xml").c_str());
		xmlNotifyList.write(output);
	}