Exemple #1
0
void Client::listContactsOnDoubleClick(QListWidgetItem* item) {
	ContactListWidgetItem* clwi = dynamic_cast<ContactListWidgetItem*>(item);

	if (clwi != nullptr) {
		ChatTab* tab = nullptr;
		if (clwi->getContact()->getContactType() == Contact::ContactType::CONTACT_IDENTITY) {
			IdentityContact* ic = dynamic_cast<IdentityContact*>(clwi->getContact());
			tab = MessageCenter::getInstance()->ensureTabOpenForIdentityContact(ic->getContactId());
		} else if (clwi->getContact()->getContactType() == Contact::ContactType::CONTACT_GROUP) {
			GroupContact* gc = dynamic_cast<GroupContact*>(clwi->getContact());
			tab = MessageCenter::getInstance()->ensureTabOpenForGroupContact(gc->getGroupId());
		} else {
			LOGGER()->warn("Could not determine the type of element the user double clicked on in the contacts list.");
			return;
		}
		
		if (tab != nullptr) {
			ui.tabWidget->setCurrentWidget(tab);
		} else {
			LOGGER()->warn("Could not open tab for user or group the user double clicked on in the contacts list.");
		}
	}	
}	
Exemple #2
0
void ContactRegistry::toFile(QString const& filename) const {
	QFile outputFile(filename);
	if (!outputFile.open(QFile::WriteOnly | QFile::Text)) {
		throw IllegalArgumentException() << QString("Could not open the specified contacts file for writing: %1").arg(filename).toStdString();
	}

	QTextStream outStream(&outputFile);
	outStream.setCodec("UTF-8"); // change the file codec to UTF-8.

	outStream << "# This is a comment line.\n";
	outStream << "# Format of this file: \n";
	outStream << "# IDENTITY : PUBKEY : Nickname\n";
	outStream << "# where \n";
	outStream << "# - IDENTITY is an eight character ID of the form [A-Z0-9]{8} and stands for a users public id,\n";
	outStream << "# - PUBKEY is an 64 character key of the form [a-fA-F0-9]{64} and stands for a users 32-Byte long-term public key,\n";
	outStream << "# - Nickname is an optional screen-name for the given identity.\n";
	outStream << "# GROUPID : GROUPOWNER : IDENTITY, IDENTITY, IDENTITY : Group Name\n";
	outStream << "# where \n";
	outStream << "# - IDENTITY is an eight character ID of the form [A-Z0-9]{8} and stands for a users public id,\n";
	outStream << "# - GROUPID is an 16 character key of the form [a-fA-F0-9]{16} and stands for a groups unique identifier,\n";
	outStream << "# - GROUPOWNER is an IDENTITY and stands for a groups creator and owner,\n";
	outStream << "# - Group Name is the displayed title of the group.\n";

	accessMutex.lock();
	// Convert identityToIdentityContactHashMap into a QMap for sorted output.
	QMap<ContactId, IdentityContact*> sortedContactMap;
	QHash<ContactId, IdentityContact*>::const_iterator itContacts = identityToIdentityContactHashMap.constBegin();
	QHash<ContactId, IdentityContact*>::const_iterator endContacts = identityToIdentityContactHashMap.constEnd();
	for (; itContacts != endContacts; ++itContacts) {
		sortedContactMap.insert(itContacts.key(), itContacts.value());
	}

	QMap<ContactId, IdentityContact*>::const_iterator itSortedContacts = sortedContactMap.constBegin();
	QMap<ContactId, IdentityContact*>::const_iterator endSortedContacts = sortedContactMap.constEnd();
	for (; itSortedContacts != endSortedContacts; ++itSortedContacts) {
		IdentityContact* ic = itSortedContacts.value();
		QString nickname = ic->getNickname();
		if (nickname.isNull() || nickname.isEmpty()) {
			nickname = "";
		}
		outStream << ic->getContactId().toQString() << " : " << QString(ic->getPublicKey().getPublicKey().toHex()) << " : " << nickname << "\n";
	}

	// Convert identityToGroupContactHashMap into a QMap for sorted output.
	QMap<GroupId, GroupContact*> sortedGroupMap;
	QHash<GroupId, GroupContact*>::const_iterator itGroups = identityToGroupContactHashMap.constBegin();
	QHash<GroupId, GroupContact*>::const_iterator endGroups = identityToGroupContactHashMap.constEnd();
	for (; itGroups != endGroups; ++itGroups) {
		sortedGroupMap.insert(itGroups.key(), itGroups.value());
	}

	QMap<GroupId, GroupContact*>::const_iterator itSortedGroups = sortedGroupMap.constBegin();
	QMap<GroupId, GroupContact*>::const_iterator endSortedGroups = sortedGroupMap.constEnd();
	for (; itSortedGroups != endSortedGroups; ++itSortedGroups) {
		GroupContact* gc = itSortedGroups.value();
		QSet<ContactId> const& members = gc->getGroupMembers();
		QSet<ContactId>::const_iterator membersIt = members.constBegin();
		QSet<ContactId>::const_iterator membersEnd = members.constEnd();
		QStringList memberIds;
		for (; membersIt != membersEnd; ++membersIt) {
			memberIds.append(membersIt->toQString());
		}
		memberIds.sort(Qt::CaseInsensitive);

		outStream << gc->getGroupId().toContactFileFormat() << " : " << memberIds.join(',') << " : " << gc->getContactName() << "\n";
	}

	accessMutex.unlock();

	outputFile.close();
}
Exemple #3
0
void Client::listContactsOnContextMenu(QPoint const& pos) {
	QPoint globalPos = ui.listContacts->viewport()->mapToGlobal(pos);

	QListWidgetItem* listItem = ui.listContacts->itemAt(pos);
	ContactListWidgetItem* clwi = dynamic_cast<ContactListWidgetItem*>(listItem);
	if (clwi != nullptr) {
		QMenu listContactsContextMenu;

		QAction* actionHeadline = nullptr;
		QAction* actionEdit = nullptr;
		QAction* actionOpenClose = nullptr;
		QAction* actionRequestSync = nullptr;

		bool isChatWindowOpen = false;
		bool isIdentityContact = false;
		bool isGroupSelfOwned = false;
		ChatTab* tab = nullptr;
		if (clwi->getContact()->getContactType() == Contact::ContactType::CONTACT_IDENTITY) {
			IdentityContact* ic = dynamic_cast<IdentityContact*>(clwi->getContact());
			isIdentityContact = true;

			actionHeadline = new QAction(QString("Identity: %1").arg(ic->getContactId().toQString()), &listContactsContextMenu);
			listContactsContextMenu.addAction(actionHeadline);
			actionEdit = new QAction("Edit Contact", &listContactsContextMenu);
			listContactsContextMenu.addAction(actionEdit);

			isChatWindowOpen = MessageCenter::getInstance()->hasTabOpenForIdentityContact(ic->getContactId());
			if (isChatWindowOpen) {
				tab = MessageCenter::getInstance()->ensureTabOpenForIdentityContact(ic->getContactId());
				actionOpenClose = new QAction("Close Chat Window", &listContactsContextMenu);
			} else {
				actionOpenClose = new QAction("Open Chat Window", &listContactsContextMenu);
			}
			listContactsContextMenu.addAction(actionOpenClose);
		} else {
			GroupContact* gc = dynamic_cast<GroupContact*>(clwi->getContact());
			isIdentityContact = false;

			actionHeadline = new QAction(QString("Group: %1").arg(gc->getGroupId().toQString()), &listContactsContextMenu);
			listContactsContextMenu.addAction(actionHeadline);
			actionEdit = new QAction("Edit Group", &listContactsContextMenu);
			listContactsContextMenu.addAction(actionEdit);

			isChatWindowOpen = MessageCenter::getInstance()->hasTabOpenForGroupContact(gc->getGroupId());
			if (isChatWindowOpen) {
				tab = MessageCenter::getInstance()->ensureTabOpenForGroupContact(gc->getGroupId());
				actionOpenClose = new QAction("Close Chat Window", &listContactsContextMenu);
			} else {
				actionOpenClose = new QAction("Open Chat Window", &listContactsContextMenu);
			}
			listContactsContextMenu.addAction(actionOpenClose);

			if (gc->getGroupOwner() == ContactRegistry::getInstance()->getSelfContact()->getContactId()) {
				isGroupSelfOwned = true;
				actionRequestSync = new QAction("Force Group Sync", &listContactsContextMenu);
			} else {
				actionRequestSync = new QAction("Request Group Sync", &listContactsContextMenu);
			}
			listContactsContextMenu.addAction(actionRequestSync);
			if (protocolClient == nullptr || !protocolClient->getIsConnected()) {
				actionRequestSync->setDisabled(true);
			}
		}

		QAction* selectedItem = listContactsContextMenu.exec(globalPos);
		if (selectedItem != nullptr) {
			if (selectedItem == actionEdit) {
				showNotYetImplementedInfo();
			} else if (selectedItem == actionOpenClose) {
				if (isChatWindowOpen) {
					if (isIdentityContact) {
						IdentityContact* ic = dynamic_cast<IdentityContact*>(clwi->getContact());
						MessageCenter::getInstance()->closeTabForIdentityContact(ic->getContactId());
					} else {
						GroupContact* gc = dynamic_cast<GroupContact*>(clwi->getContact());
						MessageCenter::getInstance()->closeTabForGroupContact(gc->getGroupId());
					}
				} else {
					if (isIdentityContact) {
						IdentityContact* ic = dynamic_cast<IdentityContact*>(clwi->getContact());
						tab = MessageCenter::getInstance()->ensureTabOpenForIdentityContact(ic->getContactId());
					} else {
						GroupContact* gc = dynamic_cast<GroupContact*>(clwi->getContact());
						tab = MessageCenter::getInstance()->ensureTabOpenForGroupContact(gc->getGroupId());
					}

					if (tab != nullptr) {
						ui.tabWidget->setCurrentWidget(tab);
					}
				}
			} else if (!isIdentityContact && (selectedItem == actionRequestSync) && (actionRequestSync != nullptr)) {
				if (protocolClient == nullptr || !protocolClient->getIsConnected()) {
					return;
				}

				GroupContact* gc = dynamic_cast<GroupContact*>(clwi->getContact());
				if (isGroupSelfOwned) {
					QMetaObject::invokeMethod(protocolClient, "resendGroupSetup", Qt::QueuedConnection, Q_ARG(GroupId const&, gc->getGroupId()));
				} else {
					QMetaObject::invokeMethod(protocolClient, "requestGroupSync", Qt::QueuedConnection, Q_ARG(GroupId const&, gc->getGroupId()));
				}
			}
		}