/* * Sets up the profile for alias and initializes wallDialog and friendDialog. */ void Facepamphlet::loginAlias(QString alias) { // Setup profile image QString profileImageSource = ":/images_section/"; if(alias.compare("Cheryl/Carol/Cristal") == 0) { profileImageSource += "cheryl"; } else if(alias.compare("Lana Kain") == 0) { profileImageSource += "lana"; } else { profileImageSource += alias.toLower(); } QPixmap image = QPixmap(profileImageSource); profileIcon->setPixmap(image.scaledToHeight(std::min(200, image.height()))); // Setup selfInfo selfInfo.image = QIcon(profileImageSource); selfInfo.alias = alias; // Setup visual layout settings for wallPostList wallPostList->setIconSize(QSize(50,50)); wallPostList->setSpacing(1); wallPostList->setWordWrap(true); // Setup visual layout settings for wallPostList friendsList->setIconSize(QSize(50,50)); // Initialize dialogs // Initialize the wallDialog (for posts to wall by friends) wallDialog = new WallDialog; // Initialize the friendsDialog (for adding friends) friendDialog = new FriendDialog(alias); // Setup connections connect(selfPostButton, SIGNAL(clicked()), this, SLOT(selfWallPost())); connect(friendRemoveButton, SIGNAL(clicked()), this, SLOT(friendRemove())); connect(friendAddButton, SIGNAL(clicked()), this, SLOT(showFriendDialog())); connect(friendWallButton, SIGNAL(clicked()), this, SLOT(showWallDialog())); // Connect with friendDialog connect(this, SIGNAL(setDefaults()), friendDialog, SLOT(addDefaultFriends())); connect(friendDialog, SIGNAL(addFriend(friendInfo)), this, SLOT(friendAdded(friendInfo))); connect(this, SIGNAL(friendRemoved(friendInfo)), friendDialog, SLOT(friendRemoved(friendInfo))); // Connect with wallDialog connect(this, SIGNAL(friendRemoved(friendInfo)), wallDialog, SLOT(friendRemoved(friendInfo))); connect(friendDialog, SIGNAL(addFriend(friendInfo)), wallDialog, SLOT(friendAdded(friendInfo))); // Emit signal to cause friendDialog to add a few default friends emit setDefaults(); // Show main window show(); }
void Core::requestFriendship(const QString& friendAddress, const QString& message) { qDebug() << "Core: requesting friendship of "+friendAddress; CString cMessage(message); int friendId = tox_add_friend(tox, CFriendAddress(friendAddress).data(), cMessage.data(), cMessage.size()); const QString userId = friendAddress.mid(0, TOX_CLIENT_ID_SIZE * 2); if (friendId < 0) { emit failedToAddFriend(userId); } else { // Update our friendAddresses bool found=false; QList<QString>& friendAddresses = Settings::getInstance().friendAddresses; for (QString& addr : friendAddresses) { if (addr.toUpper().contains(friendAddress)) { addr = friendAddress; found = true; } } if (!found) friendAddresses.append(friendAddress); emit friendAdded(friendId, userId); } saveConfiguration(); }
void Core::requestFriendship(const ToxId& friendId, const QString& message) { ToxPk friendPk = friendId.getPublicKey(); QString errorMessage = getFriendRequestErrorMessage(friendId, message); if (!errorMessage.isNull()) { emit failedToAddFriend(friendPk, errorMessage); profile.saveToxSave(); } ToxString cMessage(message); uint32_t friendNumber = tox_friend_add(tox, friendId.getBytes(), cMessage.data(), cMessage.size(), nullptr); if (friendNumber == std::numeric_limits<uint32_t>::max()) { qDebug() << "Failed to request friendship"; emit failedToAddFriend(friendPk); } else { qDebug() << "Requested friendship of " << friendNumber; Settings::getInstance().updateFriendAddress(friendId.toString()); emit friendAdded(friendNumber, friendPk); emit requestSent(friendPk, message); } profile.saveToxSave(); }
void Core::acceptFriendRequest(const QString& userId) { int friendId = tox_addfriend_norequest(tox, CUserId(userId).data()); if (friendId == -1) { emit failedToAddFriend(userId); } else { emit friendAdded(friendId, userId); } }
void Core::acceptFriendRequest(const ToxPk& friendPk) { // TODO: error handling uint32_t friendId = tox_friend_add_norequest(tox, friendPk.getBytes(), nullptr); if (friendId == std::numeric_limits<uint32_t>::max()) { emit failedToAddFriend(friendPk); } else { profile.saveToxSave(); emit friendAdded(friendId, friendPk); } }
void Core::requestFriendship(const QString& userId, const QString& message) { CString cMessage(message); int friendId = tox_addfriend(handle, CUserId(userId).data(), cMessage.data(), cMessage.size()); if (friendId == -1) { emit failedToAddFriend(userId); } else { emit friendAdded(friendId, userId); friendIdList << friendId; } }
void Core::requestFriendship(const QString& friendAddress, const QString& message) { CString cMessage(message); int friendId = tox_addfriend(tox, CFriendAddress(friendAddress).data(), cMessage.data(), cMessage.size()); const QString userId = friendAddress.mid(0, TOX_CLIENT_ID_SIZE * 2); // TODO: better error handling if (friendId < 0) { emit failedToAddFriend(userId); } else { emit friendAdded(friendId, userId); } }
void Core::acceptFriendRequest(const QString& userId) { uint32_t friendId = tox_friend_add_norequest(tox, CUserId(userId).data(), nullptr); if (friendId == std::numeric_limits<uint32_t>::max()) { emit failedToAddFriend(userId); } else { saveConfiguration(); emit friendAdded(friendId, userId); } }
void Core::requestFriendship(const QString& friendAddress, const QString& message) { qDebug() << "Core: requesting friendship of "+friendAddress; CString cMessage(message); int friendId = tox_add_friend(tox, CFriendAddress(friendAddress).data(), cMessage.data(), cMessage.size()); const QString userId = friendAddress.mid(0, TOX_CLIENT_ID_SIZE * 2); if (friendId < 0) { emit failedToAddFriend(userId); } else { emit friendAdded(friendId, userId); } saveConfiguration(); }
void Core::requestFriendship(const QString& friendAddress, const QString& message) { const QString userId = friendAddress.mid(0, TOX_PUBLIC_KEY_SIZE * 2); if (message.isEmpty()) { emit failedToAddFriend(userId, tr("You need to write a message with your request")); } else if (message.size() > TOX_MAX_FRIEND_REQUEST_LENGTH) { emit failedToAddFriend(userId, tr("Your message is too long!")); } else if (hasFriendWithAddress(friendAddress)) { emit failedToAddFriend(userId, tr("Friend is already added")); } else { CString cMessage(message); uint32_t friendId = tox_friend_add(tox, CFriendAddress(friendAddress).data(), cMessage.data(), cMessage.size(), nullptr); if (friendId == std::numeric_limits<uint32_t>::max()) { qDebug() << "Failed to request friendship"; emit failedToAddFriend(userId); } else { qDebug() << "Requested friendship of "<<friendId; // Update our friendAddresses Settings::getInstance().updateFriendAddress(friendAddress); QString inviteStr = tr("/me offers friendship."); if (message.length()) inviteStr = tr("/me offers friendship, \"%1\"").arg(message); Profile* profile = Nexus::getProfile(); if (profile->isHistoryEnabled()) profile->getHistory()->addNewMessage(userId, inviteStr, getSelfId().publicKey, QDateTime::currentDateTime(), true, QString()); emit friendAdded(friendId, userId); emit friendshipChanged(friendId); } } profile.saveToxSave(); }
void FriendsWidget::addFriend(const QString& userId, const QString& username) { QStandardItem* item = new QStandardItem(username); item->setData(userId, UserIdRole); item->setData(QString("User ID: %1").arg(userId), Qt::ToolTipRole); item->setFlags(item->flags() & ~Qt::ItemIsEditable); UserInfo info = userInfoHash[userId]; info.username = username; userInfoHash[userId] = info; emit friendAdded(userId, username); Status status = Status::Offline; setStatus(item, status); friendModel->appendRow(item); }
void Core::loadFriends() { const uint32_t friendCount = tox_self_get_friend_list_size(tox); if (friendCount > 0) { // assuming there are not that many friends to fill up the whole stack uint32_t *ids = new uint32_t[friendCount]; tox_self_get_friend_list(tox, ids); uint8_t clientId[TOX_PUBLIC_KEY_SIZE]; for (int32_t i = 0; i < static_cast<int32_t>(friendCount); ++i) { if (tox_friend_get_public_key(tox, ids[i], clientId, nullptr)) { emit friendAdded(ids[i], CUserId::toString(clientId)); const size_t nameSize = tox_friend_get_name_size(tox, ids[i], nullptr); if (nameSize && nameSize != SIZE_MAX) { uint8_t *name = new uint8_t[nameSize]; if (tox_friend_get_name(tox, ids[i], name, nullptr)) emit friendUsernameChanged(ids[i], CString::toString(name, nameSize)); delete[] name; } const size_t statusMessageSize = tox_friend_get_status_message_size(tox, ids[i], nullptr); if (statusMessageSize != SIZE_MAX) { uint8_t *statusMessage = new uint8_t[statusMessageSize]; if (tox_friend_get_status_message(tox, ids[i], statusMessage, nullptr)) { emit friendStatusMessageChanged(ids[i], CString::toString(statusMessage, statusMessageSize)); } delete[] statusMessage; } checkLastOnline(ids[i]); } } delete[] ids; } }
void Core::requestFriendship(const QString& friendAddress, const QString& message) { const QString userId = friendAddress.mid(0, TOX_PUBLIC_KEY_SIZE * 2); if (message.isEmpty()) { emit failedToAddFriend(userId, tr("You need to write a message with your request")); } else if (message.size() > TOX_MAX_FRIEND_REQUEST_LENGTH) { emit failedToAddFriend(userId, tr("Your message is too long!")); } else if (hasFriendWithAddress(friendAddress)) { emit failedToAddFriend(userId, tr("Friend is already added")); } else { qDebug() << "Core: requesting friendship of "+friendAddress; CString cMessage(message); uint32_t friendId = tox_friend_add(tox, CFriendAddress(friendAddress).data(), cMessage.data(), cMessage.size(), nullptr); if (friendId == std::numeric_limits<uint32_t>::max()) { emit failedToAddFriend(userId); } else { // Update our friendAddresses Settings::getInstance().updateFriendAdress(friendAddress); QString inviteStr = tr("/me offers friendship."); if (message.length()) inviteStr = tr("/me offers friendship, \"%1\"").arg(message); HistoryKeeper::getInstance()->addChatEntry(userId, inviteStr, getSelfId().publicKey, QDateTime::currentDateTime(), true); emit friendAdded(friendId, userId); } } saveConfiguration(); }
void Core::loadFriends() { const uint32_t friendCount = tox_self_get_friend_list_size(tox); if (friendCount <= 0) { return; } // assuming there are not that many friends to fill up the whole stack uint32_t* ids = new uint32_t[friendCount]; tox_self_get_friend_list(tox, ids); uint8_t friendPk[TOX_PUBLIC_KEY_SIZE] = {0x00}; for (uint32_t i = 0; i < friendCount; ++i) { if (!tox_friend_get_public_key(tox, ids[i], friendPk, nullptr)) { continue; } emit friendAdded(ids[i], ToxPk(friendPk)); GET_FRIEND_PROPERTY(Username, tox_friend_get_name, true); GET_FRIEND_PROPERTY(StatusMessage, tox_friend_get_status_message, false); checkLastOnline(ids[i]); } delete[] ids; }
void Core::loadFriends() { const uint32_t friendCount = tox_count_friendlist(tox); if (friendCount > 0) { // assuming there are not that many friends to fill up the whole stack int32_t *ids = new int32_t[friendCount]; tox_get_friendlist(tox, ids, friendCount); uint8_t clientId[TOX_CLIENT_ID_SIZE]; for (int32_t i = 0; i < static_cast<int32_t>(friendCount); ++i) { if (tox_get_client_id(tox, ids[i], clientId) == 0) { emit friendAdded(ids[i], CUserId::toString(clientId)); const int nameSize = tox_get_name_size(tox, ids[i]); if (nameSize > 0) { uint8_t *name = new uint8_t[nameSize]; if (tox_get_name(tox, ids[i], name) == nameSize) { emit friendUsernameLoaded(ids[i], CString::toString(name, nameSize)); } delete[] name; } const int statusMessageSize = tox_get_status_message_size(tox, ids[i]); if (statusMessageSize > 0) { uint8_t *statusMessage = new uint8_t[statusMessageSize]; if (tox_get_status_message(tox, ids[i], statusMessage, statusMessageSize) == statusMessageSize) { emit friendStatusMessageLoaded(ids[i], CString::toString(statusMessage, statusMessageSize)); } delete[] statusMessage; } checkLastOnline(ids[i]); } } delete[] ids; } }
void Core::requestFriendship(const ToxId& friendAddress, const QString& message) { ToxPk friendPk = friendAddress.getPublicKey(); if (!friendAddress.isValid()) { emit failedToAddFriend(friendPk, tr("Invalid Tox ID")); } else if (message.isEmpty()) { emit failedToAddFriend(friendPk, tr("You need to write a message with your request")); } else if (message.size() > TOX_MAX_FRIEND_REQUEST_LENGTH) { emit failedToAddFriend(friendPk, tr("Your message is too long!")); } else if (hasFriendWithPublicKey(friendPk)) { emit failedToAddFriend(friendPk, tr("Friend is already added")); } else { CString cMessage(message); uint32_t friendId = tox_friend_add(tox, friendAddress.getBytes(), cMessage.data(), cMessage.size(), nullptr); if (friendId == std::numeric_limits<uint32_t>::max()) { qDebug() << "Failed to request friendship"; emit failedToAddFriend(friendPk); } else { qDebug() << "Requested friendship of " << friendId; // Update our friendAddresses Settings::getInstance().updateFriendAddress(friendAddress.toString()); // TODO: start: this really shouldn't be in Core QString inviteStr = tr("/me offers friendship."); if (message.length()) inviteStr = tr("/me offers friendship, \"%1\"").arg(message); Profile* profile = Nexus::getProfile(); if (profile->isHistoryEnabled()) { profile->getHistory()->addNewMessage(friendAddress.toString(), inviteStr, getSelfId().getPublicKey().toString(), QDateTime::currentDateTime(), true, QString()); } // TODO: end emit friendAdded(friendId, friendAddress.getPublicKey()); emit friendshipChanged(friendId); } } profile.saveToxSave(); }