Ejemplo n.º 1
0
bool accounts::read_data() {

	QFile file(core_i->get_config_dir() + "/" + ACCOUNTS_DATA_FILENAME);
	QFileInfo info(file);
	if(!file.exists()) {
		qDebug() << "File not found:" << info.absoluteFilePath();
		return true;
	}

	QString error_str;
	int error_line, error_col;
	QDomDocument doc;
	if(!doc.setContent(&file, false, &error_str, &error_line, &error_col)) {
		qWarning() << "Accounts: failed to load XML file ("<< info.absoluteFilePath() << ") - error on line" << error_line << ":" << error_str;
		return false;
	}
	
	QDomElement root = doc.documentElement();
	if(root.tagName() != "accounts") {
		qWarning() << "Accounts: XML contains no 'accounts' element";
		return false;
	}
	
	QDomNode node = root.firstChild();
	while(!node.isNull()) {
		if(node.toElement().tagName() == "account-data")
			parse_account_node(node.toElement());
		node = node.nextSibling();
	}
	
	if(options) options->reset();

	return true;
}
Ejemplo n.º 2
0
bool accounts::save_data() {
	QDomDocument doc;
	QDomElement root = doc.createElement("accounts");
	doc.appendChild(root);	
	QMapIterator<ProtocolI *, QMap<QString, Account *> > i(account_list);
	while(i.hasNext()) {
		i.next();
		QMapIterator<QString, Account *> j(i.value());
		while(j.hasNext()) {
			j.next();
			root.appendChild(toDOM(doc, j.value()));
		}
	}

	if(!QDir::root().exists(core_i->get_config_dir()))
		QDir::root().mkpath(core_i->get_config_dir());

	QFile file(core_i->get_config_dir() + "/" + ACCOUNTS_DATA_FILENAME);
	QFileInfo info(file);
	if(!file.open(QIODevice::WriteOnly)) {
		qWarning() << "Accounts: could not write XML to" << info.absoluteFilePath();
		return false;
	}
	QTextStream st(&file);
	st << doc.toString();
	file.close();
	return true;
}