1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

#2167 fix: qTox should check if string in "Add friend" input field is 64 chars long

This commit is contained in:
bitok 2015-10-10 16:24:23 +03:00
parent 375c34c079
commit f5bffa0f0c
2 changed files with 15 additions and 6 deletions

View File

@ -54,10 +54,13 @@ AddFriendForm::AddFriendForm()
head->setLayout(&headLayout);
headLayout.addWidget(&headLabel);
connect(&toxId,&QLineEdit::returnPressed, this, &AddFriendForm::onSendTriggered);
connect(&toxId, &QLineEdit::returnPressed, this, &AddFriendForm::onSendTriggered);
connect(&toxId, &QLineEdit::textChanged, this, &AddFriendForm::onIdChanged);
connect(&sendButton, SIGNAL(clicked()), this, SLOT(onSendTriggered()));
connect(Nexus::getCore(), &Core::usernameSet, this, &AddFriendForm::onUsernameSet);
onIdChanged(QString()); //validate empty id
Translator::registerHandler(std::bind(&AddFriendForm::retranslateUi, this), this);
}
@ -105,11 +108,7 @@ void AddFriendForm::onSendTriggered()
{
QString id = toxId.text().trimmed();
if (id.isEmpty())
{
GUI::showWarning(tr("Couldn't add friend"), tr("Please fill in a valid Tox ID","Tox ID of the friend you're sending a friend request to"));
}
else if (ToxId::isToxId(id))
if (ToxId::isToxId(id))
{
if (id.toUpper() == Core::getInstance()->getSelfId().toString().toUpper())
GUI::showWarning(tr("Couldn't add friend"), tr("You can't add yourself as a friend!","When trying to add your own Tox ID as friend"));
@ -143,6 +142,15 @@ Ignore the proxy and connect to the Internet directly?"), QMessageBox::Yes|QMess
}
}
void AddFriendForm::onIdChanged(const QString &id)
{
QString tId = id.trimmed();
bool isValidId = ToxId::isToxId(tId) || QRegExp("\\S+@\\S+").exactMatch(tId);
toxId.setStyleSheet(isValidId ? QStringLiteral("") : QStringLiteral("QLineEdit { background-color: #FFC1C1; }"));
toxId.setToolTip(isValidId ? QStringLiteral("") : tr("Invalid Tox ID format. Is's must be 76 digital or alphabet characters length or similar name@domain.com."));
sendButton.setEnabled(isValidId);
}
void AddFriendForm::setIdFromClipboard()
{
QClipboard* clipboard = QApplication::clipboard();

View File

@ -49,6 +49,7 @@ public slots:
private slots:
void onSendTriggered();
void onIdChanged(const QString &id);
private:
void retranslateUi();