Ejemplo n.º 1
0
void ContactEditWizardPageDone::initializePage() {
	// all data in the Info section was given, now create the group
	// Generate new random ID as group identifier
	quint64 newGroupId = GroupContact::generateRandomGroupId();
	GroupContact* gc = new GroupContact(GroupId(clientConfiguration->getClientIdentity(), newGroupId));
	gc->setGroupName(field("edtName").toString());
	gc->addMember(clientConfiguration->getClientIdentity());

	// Send messages to members
	QMetaObject::invokeMethod(protocolClient, "sendGroupCreation", Q_ARG(quint64, newGroupId), Q_ARG(bool, true));
	QThread::msleep(100);
	QMetaObject::invokeMethod(protocolClient, "sendGroupTitle", Q_ARG(quint64, newGroupId), Q_ARG(QString const&, field("edtName").toString()));
}
Ejemplo n.º 2
0
void ContactRegistry::fromFile(QString const& filename, bool dryRun) {
	if (!QFile::exists(filename)) {
		throw IllegalArgumentException() << QString("Could not open the specified contacts file as it does not exist: %1").arg(filename).toStdString();
	}
	QFile inputFile(filename);
	if (!inputFile.open(QFile::ReadOnly | QFile::Text)) {
		throw IllegalArgumentException() << QString("Could not open the specified contacts file for reading: %1").arg(filename).toStdString();
	}

	QRegExp commentRegExp("^\\s*#.*$", Qt::CaseInsensitive, QRegExp::RegExp2);
	QRegExp identityRegExp("^\\s*([A-Z0-9]{8})\\s*:\\s*([a-fA-F0-9]{64})\\s*(?::\\s*(.*)\\s*)?$", Qt::CaseInsensitive, QRegExp::RegExp2);
	QRegExp groupRegExp("^\\s*([a-fA-F0-9]{16})\\s*:\\s*([A-Z0-9]{8})\\s*:\\s*([A-Z0-9]{8}(?:\\s*,\\s*[A-Z0-9]{8})*)\\s*:\\s*(.*)\\s*$", Qt::CaseInsensitive, QRegExp::RegExp2);

	QTextStream in(&inputFile);
	in.setCodec("UTF-8"); // change the file codec to UTF-8.
	while (!in.atEnd()) {
		QString line = in.readLine().trimmed();
		if (line.isEmpty() || commentRegExp.exactMatch(line)) {
			continue;
		} else if (identityRegExp.exactMatch(line)) {
			if (!dryRun) {
				accessMutex.lock();

				ContactId const contactId(identityRegExp.cap(1));
				IdentityContact* iContact = new IdentityContact(contactId, PublicKey::fromHexString(identityRegExp.cap(2)));
				if (!identityRegExp.cap(3).trimmed().isEmpty()) {
					// Nickname given.
					iContact->setNickname(identityRegExp.cap(3).trimmed());
				}
				connectContact(iContact);
				identityToIdentityContactHashMap.insert(contactId, iContact);

				accessMutex.unlock();
			}
		} else if (groupRegExp.exactMatch(line)) {
			if (!dryRun) {
				accessMutex.lock();

				quint64 groupIdentity = IdentityHelper::groupIdByteArrayToUint64(QByteArray::fromHex(groupRegExp.cap(1).toLatin1()));
				quint64 groupOwner = IdentityHelper::identityStringToUint64(groupRegExp.cap(2));
				GroupContact* gContact = new GroupContact(GroupId(groupOwner, groupIdentity));
				if (!groupRegExp.cap(4).trimmed().isEmpty()) {
					gContact->setGroupName(groupRegExp.cap(4).trimmed());
				}

				QStringList ids = groupRegExp.cap(3).split(',', QString::SkipEmptyParts);
				if (ids.size() == 0) {
					throw IllegalArgumentException() << QString("Invalid or ill-formated line in contacts file \"%1\".\nProblematic line: %2").arg(filename).arg(line).toStdString();
				}

				QStringList::const_iterator it = ids.constBegin();
				QStringList::const_iterator end = ids.constEnd();
				for (; it != end; ++it) {
					QString trimmedId(it->trimmed());
					ContactId const memberId(trimmedId);
					gContact->addMember(memberId);
				}

				connectContact(gContact);
				identityToGroupContactHashMap.insert(GroupId(groupOwner, groupIdentity), gContact);

				accessMutex.unlock();
			}
		} else {
			throw IllegalArgumentException() << QString("Invalid or ill-formated line in contacts file \"%1\".\nProblematic line: %2").arg(filename).arg(line).toStdString();
		}
	}

	inputFile.close();
	if (!dryRun) {
		emit identitiesChanged();
	}
}