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:
parent
b126d21922
commit
4afd13839a
|
@ -17,11 +17,11 @@
|
||||||
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "src/net/toxuri.h"
|
#include "src/net/toxuri.h"
|
||||||
#include "src/core/core.h"
|
#include "src/core/core.h"
|
||||||
#include "src/net/toxme.h"
|
#include "src/net/toxme.h"
|
||||||
#include "src/nexus.h"
|
#include "src/nexus.h"
|
||||||
|
#include "src/widget/gui.h"
|
||||||
#include "src/widget/tool/friendrequestdialog.h"
|
#include "src/widget/tool/friendrequestdialog.h"
|
||||||
#include <QByteArray>
|
#include <QByteArray>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
@ -75,43 +75,34 @@ bool handleToxURI(const QString& toxURI)
|
||||||
QString toxaddr = toxURI.mid(4);
|
QString toxaddr = toxURI.mid(4);
|
||||||
|
|
||||||
ToxId toxId(toxaddr);
|
ToxId toxId(toxaddr);
|
||||||
|
QString error = QString();
|
||||||
if (!toxId.isValid()) {
|
if (!toxId.isValid()) {
|
||||||
toxId = Toxme::lookup(toxaddr);
|
toxId = Toxme::lookup(toxaddr);
|
||||||
if (!toxId.isValid()) {
|
if (!toxId.isValid()) {
|
||||||
QMessageBox* messageBox =
|
error = QMessageBox::tr("%1 is not a valid Toxme address.").arg(toxaddr);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
} 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()) {
|
if (!error.isEmpty()) {
|
||||||
QMessageBox* messageBox =
|
GUI::showWarning(QMessageBox::tr("Couldn't add friend"), error);
|
||||||
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();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ToxURIDialog* dialog = new ToxURIDialog(
|
const QString defaultMessage = QObject::tr("%1 here! Tox me maybe?",
|
||||||
0, toxaddr,
|
"Default message in Tox URI friend requests. Write something appropriate!");
|
||||||
QObject::tr("%1 here! Tox me maybe?",
|
const QString username = Nexus::getCore()->getUsername();
|
||||||
"Default message in Tox URI friend requests. Write something appropriate!")
|
ToxURIDialog* dialog = new ToxURIDialog(nullptr, toxaddr, defaultMessage.arg(username));
|
||||||
.arg(Nexus::getCore()->getUsername()));
|
|
||||||
QObject::connect(dialog, &ToxURIDialog::finished, [=](int result) {
|
QObject::connect(dialog, &ToxURIDialog::finished, [=](int result) {
|
||||||
if (result == QDialog::Accepted)
|
if (result == QDialog::Accepted) {
|
||||||
Core::getInstance()->requestFriendship(toxId, dialog->getRequestMessage());
|
Core::getInstance()->requestFriendship(toxId, dialog->getRequestMessage());
|
||||||
|
}
|
||||||
|
|
||||||
dialog->deleteLater();
|
dialog->deleteLater();
|
||||||
});
|
});
|
||||||
|
|
||||||
dialog->open();
|
dialog->open();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user