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

refactor(toxuri): Add using GUI to show warning

This commit is contained in:
Diadlo 2017-05-06 15:04:08 +03:00
parent b126d21922
commit 4afd13839a
No known key found for this signature in database
GPG Key ID: 5AF9F2E29107C727

View File

@ -17,11 +17,11 @@
along with qTox. If not, see <http://www.gnu.org/licenses/>.
*/
#include "src/net/toxuri.h"
#include "src/core/core.h"
#include "src/net/toxme.h"
#include "src/nexus.h"
#include "src/widget/gui.h"
#include "src/widget/tool/friendrequestdialog.h"
#include <QByteArray>
#include <QCoreApplication>
@ -75,43 +75,34 @@ bool handleToxURI(const QString& toxURI)
QString toxaddr = toxURI.mid(4);
ToxId toxId(toxaddr);
QString error = QString();
if (!toxId.isValid()) {
toxId = Toxme::lookup(toxaddr);
if (!toxId.isValid()) {
QMessageBox* messageBox =
new QMessageBox(QMessageBox::Warning, QMessageBox::tr("Couldn't add friend"),
QMessageBox::tr("%1 is not a valid Toxme address.").arg(toxaddr),
QMessageBox::Ok, nullptr);
messageBox->setButtonText(QMessageBox::Ok, QMessageBox::tr("Ok"));
QObject::connect(messageBox, &QMessageBox::finished, messageBox, &QMessageBox::deleteLater);
messageBox->show();
return false;
error = QMessageBox::tr("%1 is not a valid Toxme address.").arg(toxaddr);
}
} else if (toxId == core->getSelfId()) {
error = QMessageBox::tr("You can't add yourself as a friend!",
"When trying to add your own Tox ID as friend");
}
if (toxId == core->getSelfId()) {
QMessageBox* messageBox =
new QMessageBox(QMessageBox::Warning, QMessageBox::tr("Couldn't add friend"),
QMessageBox::tr("You can't add yourself as a friend!",
"When trying to add your own Tox ID as friend"),
QMessageBox::Ok, nullptr);
messageBox->setButtonText(QMessageBox::Ok, QMessageBox::tr("Ok"));
QObject::connect(messageBox, &QMessageBox::finished, messageBox, &QMessageBox::deleteLater);
messageBox->show();
if (!error.isEmpty()) {
GUI::showWarning(QMessageBox::tr("Couldn't add friend"), error);
return false;
}
ToxURIDialog* dialog = new ToxURIDialog(
0, toxaddr,
QObject::tr("%1 here! Tox me maybe?",
"Default message in Tox URI friend requests. Write something appropriate!")
.arg(Nexus::getCore()->getUsername()));
const QString defaultMessage = QObject::tr("%1 here! Tox me maybe?",
"Default message in Tox URI friend requests. Write something appropriate!");
const QString username = Nexus::getCore()->getUsername();
ToxURIDialog* dialog = new ToxURIDialog(nullptr, toxaddr, defaultMessage.arg(username));
QObject::connect(dialog, &ToxURIDialog::finished, [=](int result) {
if (result == QDialog::Accepted)
if (result == QDialog::Accepted) {
Core::getInstance()->requestFriendship(toxId, dialog->getRequestMessage());
}
dialog->deleteLater();
});
dialog->open();
return true;