|
|
|
@ -19,7 +19,6 @@
@@ -19,7 +19,6 @@
|
|
|
|
|
|
|
|
|
|
#include "src/net/toxuri.h" |
|
|
|
|
#include "src/core/core.h" |
|
|
|
|
#include "src/nexus.h" |
|
|
|
|
#include "src/widget/gui.h" |
|
|
|
|
#include "src/widget/tool/friendrequestdialog.h" |
|
|
|
|
#include <QByteArray> |
|
|
|
@ -34,39 +33,21 @@
@@ -34,39 +33,21 @@
|
|
|
|
|
#include <QThread> |
|
|
|
|
#include <QVBoxLayout> |
|
|
|
|
|
|
|
|
|
bool toxURIEventHandler(const QByteArray& eventData) |
|
|
|
|
{ |
|
|
|
|
if (!eventData.startsWith("tox:")) |
|
|
|
|
return false; |
|
|
|
|
|
|
|
|
|
handleToxURI(eventData); |
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief Shows a dialog asking whether or not to add this tox address as a friend. |
|
|
|
|
* @note Will wait until the core is ready first. |
|
|
|
|
* @param toxURI Tox URI to try to add. |
|
|
|
|
* @return True, if tox URI is correct, false otherwise. |
|
|
|
|
*/ |
|
|
|
|
bool handleToxURI(const QString& toxURI) |
|
|
|
|
bool ToxURIDialog::handleToxURI(const QString& toxURI) |
|
|
|
|
{ |
|
|
|
|
Nexus& nexus = Nexus::getInstance(); |
|
|
|
|
Core* core = nexus.getCore(); |
|
|
|
|
|
|
|
|
|
while (!core) { |
|
|
|
|
core = nexus.getCore(); |
|
|
|
|
qApp->processEvents(); |
|
|
|
|
QThread::msleep(10); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
QString toxaddr = toxURI.mid(4); |
|
|
|
|
|
|
|
|
|
ToxId toxId(toxaddr); |
|
|
|
|
QString error = QString(); |
|
|
|
|
if (!toxId.isValid()) { |
|
|
|
|
error = QMessageBox::tr("%1 is not a valid Tox address.").arg(toxaddr); |
|
|
|
|
} else if (toxId == core->getSelfId()) { |
|
|
|
|
} 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"); |
|
|
|
|
} |
|
|
|
@ -76,35 +57,41 @@ bool handleToxURI(const QString& toxURI)
@@ -76,35 +57,41 @@ bool handleToxURI(const QString& toxURI)
|
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
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) { |
|
|
|
|
setUserId(toxURI); |
|
|
|
|
|
|
|
|
|
int result = exec(); |
|
|
|
|
if (result == QDialog::Accepted) { |
|
|
|
|
Core::getInstance()->requestFriendship(toxId, dialog->getRequestMessage()); |
|
|
|
|
core.requestFriendship(toxId, getRequestMessage()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
dialog->deleteLater(); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
dialog->open(); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ToxURIDialog::ToxURIDialog(QWidget* parent, const QString& userId, const QString& message) |
|
|
|
|
void ToxURIDialog::setUserId(const QString& userId) |
|
|
|
|
{ |
|
|
|
|
friendsLabel->setText(tr("Do you want to add %1 as a friend?").arg(userId)); |
|
|
|
|
userIdEdit->setText(userId); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ToxURIDialog::ToxURIDialog(QWidget* parent, Core& _core) |
|
|
|
|
: QDialog(parent) |
|
|
|
|
, core{_core} |
|
|
|
|
{ |
|
|
|
|
const QString defaultMessage = |
|
|
|
|
QObject::tr("%1 here! Tox me maybe?", |
|
|
|
|
"Default message in Tox URI friend requests. Write something appropriate!"); |
|
|
|
|
const QString username = core.getUsername(); |
|
|
|
|
const QString message = defaultMessage.arg(username); |
|
|
|
|
|
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); |
|
|
|
|
setWindowTitle(tr("Add a friend", "Title of the window to add a friend through Tox URI")); |
|
|
|
|
|
|
|
|
|
QLabel* friendsLabel = new QLabel(tr("Do you want to add %1 as a friend?").arg(userId), this); |
|
|
|
|
QLabel* userIdLabel = new QLabel(tr("User ID:"), this); |
|
|
|
|
QLineEdit* userIdEdit = new QLineEdit(userId, this); |
|
|
|
|
friendsLabel = new QLabel("", this); |
|
|
|
|
userIdEdit = new QLineEdit("", this); |
|
|
|
|
userIdEdit->setCursorPosition(0); |
|
|
|
|
userIdEdit->setReadOnly(true); |
|
|
|
|
|
|
|
|
|
QLabel* userIdLabel = new QLabel(tr("User ID:"), this); |
|
|
|
|
QLabel* messageLabel = new QLabel(tr("Friend request message:"), this); |
|
|
|
|
messageEdit = new QPlainTextEdit(message, this); |
|
|
|
|
|
|
|
|
|