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:
parent
375c34c079
commit
f5bffa0f0c
|
@ -54,10 +54,13 @@ AddFriendForm::AddFriendForm()
|
||||||
head->setLayout(&headLayout);
|
head->setLayout(&headLayout);
|
||||||
headLayout.addWidget(&headLabel);
|
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(&sendButton, SIGNAL(clicked()), this, SLOT(onSendTriggered()));
|
||||||
connect(Nexus::getCore(), &Core::usernameSet, this, &AddFriendForm::onUsernameSet);
|
connect(Nexus::getCore(), &Core::usernameSet, this, &AddFriendForm::onUsernameSet);
|
||||||
|
|
||||||
|
onIdChanged(QString()); //validate empty id
|
||||||
|
|
||||||
Translator::registerHandler(std::bind(&AddFriendForm::retranslateUi, this), this);
|
Translator::registerHandler(std::bind(&AddFriendForm::retranslateUi, this), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,11 +108,7 @@ void AddFriendForm::onSendTriggered()
|
||||||
{
|
{
|
||||||
QString id = toxId.text().trimmed();
|
QString id = toxId.text().trimmed();
|
||||||
|
|
||||||
if (id.isEmpty())
|
if (ToxId::isToxId(id))
|
||||||
{
|
|
||||||
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 (id.toUpper() == Core::getInstance()->getSelfId().toString().toUpper())
|
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"));
|
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()
|
void AddFriendForm::setIdFromClipboard()
|
||||||
{
|
{
|
||||||
QClipboard* clipboard = QApplication::clipboard();
|
QClipboard* clipboard = QApplication::clipboard();
|
||||||
|
|
|
@ -49,6 +49,7 @@ public slots:
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void onSendTriggered();
|
void onSendTriggered();
|
||||||
|
void onIdChanged(const QString &id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user