2014-07-07 00:19:45 +08:00
|
|
|
/*
|
2016-11-28 21:33:38 +08:00
|
|
|
Copyright © 2014-2015 by The qTox Project Contributors
|
2015-06-06 09:40:08 +08:00
|
|
|
|
2014-07-07 00:19:45 +08:00
|
|
|
This file is part of qTox, a Qt-based graphical interface for Tox.
|
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
qTox is libre software: you can redistribute it and/or modify
|
2014-07-07 00:19:45 +08:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2015-06-06 09:40:08 +08:00
|
|
|
|
|
|
|
qTox is distributed in the hope that it will be useful,
|
2014-07-07 00:19:45 +08:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2015-06-06 09:40:08 +08:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2014-07-07 00:19:45 +08:00
|
|
|
|
2015-06-06 09:40:08 +08:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
2014-07-07 00:19:45 +08:00
|
|
|
*/
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
#include "addfriendform.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/core/core.h"
|
|
|
|
#include "src/net/toxme.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "src/net/toxme.h"
|
|
|
|
#include "src/nexus.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/persistence/settings.h"
|
|
|
|
#include "src/widget/contentlayout.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "src/widget/gui.h"
|
2016-12-19 10:26:26 +08:00
|
|
|
#include "src/widget/tool/croppinglabel.h"
|
2017-02-26 19:52:45 +08:00
|
|
|
#include "src/widget/translator.h"
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
|
|
|
#include <QErrorMessage>
|
|
|
|
#include <QFont>
|
2017-02-17 10:14:16 +08:00
|
|
|
#include <QFileDialog>
|
2017-02-26 19:52:45 +08:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QRegularExpression>
|
2016-02-21 07:45:18 +08:00
|
|
|
#include <QScrollArea>
|
2017-02-26 19:52:45 +08:00
|
|
|
#include <QSignalMapper>
|
|
|
|
#include <QTabWidget>
|
|
|
|
#include <QWindow>
|
|
|
|
#include <tox/tox.h>
|
2014-11-06 06:27:51 +08:00
|
|
|
|
2016-07-27 06:20:39 +08:00
|
|
|
/**
|
2016-08-01 16:21:23 +08:00
|
|
|
* @var QString AddFriendForm::lastUsername
|
|
|
|
* @brief Cached username so we can retranslate the invite message
|
|
|
|
*/
|
2016-07-27 06:20:39 +08:00
|
|
|
|
2014-11-06 22:12:10 +08:00
|
|
|
AddFriendForm::AddFriendForm()
|
2014-11-06 06:27:51 +08:00
|
|
|
{
|
2016-02-21 05:32:57 +08:00
|
|
|
tabWidget = new QTabWidget();
|
|
|
|
main = new QWidget(tabWidget), head = new QWidget();
|
2014-06-25 04:11:11 +08:00
|
|
|
QFont bold;
|
|
|
|
bold.setBold(true);
|
|
|
|
headLabel.setFont(bold);
|
2015-10-13 06:32:04 +08:00
|
|
|
toxIdLabel.setTextFormat(Qt::RichText);
|
2014-06-25 04:11:11 +08:00
|
|
|
|
2017-02-17 10:14:16 +08:00
|
|
|
main->setLayout(&layout);
|
|
|
|
layout.addWidget(&toxIdLabel);
|
|
|
|
layout.addWidget(&toxId);
|
|
|
|
layout.addWidget(&messageLabel);
|
|
|
|
layout.addWidget(&message);
|
|
|
|
layout.addWidget(&sendButton);
|
2016-02-21 05:32:57 +08:00
|
|
|
tabWidget->addTab(main, QString());
|
2017-02-17 10:14:16 +08:00
|
|
|
|
|
|
|
importContacts = new QWidget(tabWidget);
|
|
|
|
importContacts->setLayout(&importContactsLayout);
|
|
|
|
importFileLine.addWidget(&importFileLabel);
|
|
|
|
importFileLine.addStretch();
|
|
|
|
importFileLine.addWidget(&importFileButton);
|
|
|
|
importContactsLayout.addLayout(&importFileLine);
|
|
|
|
importContactsLayout.addWidget(&importMessageLabel);
|
|
|
|
importContactsLayout.addWidget(&importMessage);
|
|
|
|
importContactsLayout.addWidget(&importSendButton);
|
|
|
|
tabWidget->addTab(importContacts, QString());
|
|
|
|
|
2016-02-21 05:32:57 +08:00
|
|
|
QScrollArea* scrollArea = new QScrollArea(tabWidget);
|
|
|
|
QWidget* requestWidget = new QWidget(tabWidget);
|
|
|
|
scrollArea->setWidget(requestWidget);
|
|
|
|
scrollArea->setWidgetResizable(true);
|
|
|
|
requestsLayout = new QVBoxLayout(requestWidget);
|
|
|
|
requestsLayout->addStretch(1);
|
|
|
|
tabWidget->addTab(scrollArea, QString());
|
2015-08-21 05:58:03 +08:00
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
head->setLayout(&headLayout);
|
|
|
|
headLayout.addWidget(&headLabel);
|
|
|
|
|
2015-10-10 21:24:23 +08:00
|
|
|
connect(&toxId, &QLineEdit::returnPressed, this, &AddFriendForm::onSendTriggered);
|
|
|
|
connect(&toxId, &QLineEdit::textChanged, this, &AddFriendForm::onIdChanged);
|
2016-02-21 05:32:57 +08:00
|
|
|
connect(tabWidget, &QTabWidget::currentChanged, this, &AddFriendForm::onCurrentChanged);
|
2017-02-17 10:14:16 +08:00
|
|
|
connect(&sendButton, &QPushButton::clicked, this, &AddFriendForm::onSendTriggered);
|
|
|
|
connect(&importSendButton, &QPushButton::clicked, this, &AddFriendForm::onImportSendClicked);
|
|
|
|
connect(&importFileButton, &QPushButton::clicked, this, &AddFriendForm::onImportOpenClicked);
|
2015-02-24 21:10:51 +08:00
|
|
|
connect(Nexus::getCore(), &Core::usernameSet, this, &AddFriendForm::onUsernameSet);
|
2015-06-06 03:37:01 +08:00
|
|
|
|
2016-11-27 00:49:29 +08:00
|
|
|
// accessibility stuff
|
2017-02-26 19:52:45 +08:00
|
|
|
toxIdLabel.setAccessibleDescription(
|
|
|
|
tr("Tox ID, either 76 hexadecimal characters or name@example.com"));
|
2016-11-27 00:49:29 +08:00
|
|
|
toxId.setAccessibleDescription(tr("Type in Tox ID of your friend"));
|
|
|
|
messageLabel.setAccessibleDescription(tr("Friend request message"));
|
2017-02-26 19:52:45 +08:00
|
|
|
message.setAccessibleDescription(tr(
|
|
|
|
"Type message to send with the friend request or leave empty to send a default message"));
|
2017-04-19 14:44:47 +08:00
|
|
|
message.setTabChangesFocus(true);
|
2016-11-27 00:49:29 +08:00
|
|
|
|
2016-02-21 05:32:57 +08:00
|
|
|
retranslateUi();
|
2015-06-06 03:37:01 +08:00
|
|
|
Translator::registerHandler(std::bind(&AddFriendForm::retranslateUi, this), this);
|
2016-02-21 05:32:57 +08:00
|
|
|
|
|
|
|
int size = Settings::getInstance().getFriendRequestSize();
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
for (int i = 0; i < size; ++i) {
|
2016-04-21 05:36:02 +08:00
|
|
|
Settings::Request request = Settings::getInstance().getFriendRequest(i);
|
|
|
|
addFriendRequestWidget(request.address, request.message);
|
2016-02-21 05:32:57 +08:00
|
|
|
}
|
2014-07-01 02:05:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
AddFriendForm::~AddFriendForm()
|
|
|
|
{
|
2015-06-06 03:37:01 +08:00
|
|
|
Translator::unregister(this);
|
2014-07-01 02:05:01 +08:00
|
|
|
head->deleteLater();
|
2016-02-21 05:32:57 +08:00
|
|
|
tabWidget->deleteLater();
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
2015-06-17 02:25:19 +08:00
|
|
|
bool AddFriendForm::isShown() const
|
2014-06-25 04:11:11 +08:00
|
|
|
{
|
2017-02-26 19:52:45 +08:00
|
|
|
if (head->isVisible()) {
|
2015-07-20 22:03:01 +08:00
|
|
|
head->window()->windowHandle()->alert(0);
|
2015-06-17 02:25:19 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFriendForm::show(ContentLayout* contentLayout)
|
|
|
|
{
|
2016-02-21 07:45:18 +08:00
|
|
|
contentLayout->mainContent->layout()->addWidget(tabWidget);
|
|
|
|
contentLayout->mainHead->layout()->addWidget(head);
|
2016-02-21 05:32:57 +08:00
|
|
|
tabWidget->show();
|
2014-06-25 04:11:11 +08:00
|
|
|
head->show();
|
2015-03-28 00:43:25 +08:00
|
|
|
setIdFromClipboard();
|
2015-03-26 19:20:55 +08:00
|
|
|
toxId.setFocus();
|
2016-06-27 16:51:34 +08:00
|
|
|
|
|
|
|
// Fix #3421
|
|
|
|
// Needed to update tab after opening window
|
|
|
|
int index = tabWidget->currentIndex();
|
|
|
|
onCurrentChanged(index);
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
|
|
|
|
2014-11-06 22:12:10 +08:00
|
|
|
QString AddFriendForm::getMessage() const
|
2014-07-01 02:05:01 +08:00
|
|
|
{
|
2014-11-06 22:12:10 +08:00
|
|
|
const QString msg = message.toPlainText();
|
|
|
|
return !msg.isEmpty() ? msg : message.placeholderText();
|
2014-07-01 02:05:01 +08:00
|
|
|
}
|
|
|
|
|
2017-02-17 10:14:16 +08:00
|
|
|
QString AddFriendForm::getImportMessage() const
|
|
|
|
{
|
|
|
|
const QString msg = importMessage.toPlainText();
|
|
|
|
return msg.isEmpty() ? importMessage.placeholderText() : msg;
|
|
|
|
}
|
|
|
|
|
2016-02-21 05:32:57 +08:00
|
|
|
void AddFriendForm::setMode(Mode mode)
|
|
|
|
{
|
|
|
|
tabWidget->setCurrentIndex(mode);
|
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
bool AddFriendForm::addFriendRequest(const QString& friendAddress, const QString& message)
|
2016-02-21 05:32:57 +08:00
|
|
|
{
|
2017-02-26 19:52:45 +08:00
|
|
|
if (Settings::getInstance().addFriendRequest(friendAddress, message)) {
|
2016-02-25 23:46:40 +08:00
|
|
|
addFriendRequestWidget(friendAddress, message);
|
2017-02-17 10:14:16 +08:00
|
|
|
if (isShown()) {
|
2016-02-26 19:15:31 +08:00
|
|
|
onCurrentChanged(tabWidget->currentIndex());
|
2017-02-17 10:14:16 +08:00
|
|
|
}
|
2016-07-07 17:55:53 +08:00
|
|
|
|
2016-02-25 23:46:40 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2016-02-21 05:32:57 +08:00
|
|
|
}
|
|
|
|
|
2015-02-24 21:10:51 +08:00
|
|
|
void AddFriendForm::onUsernameSet(const QString& username)
|
|
|
|
{
|
2015-06-06 03:37:01 +08:00
|
|
|
lastUsername = username;
|
|
|
|
retranslateUi();
|
2015-02-24 21:10:51 +08:00
|
|
|
}
|
|
|
|
|
2014-06-25 04:11:11 +08:00
|
|
|
void AddFriendForm::onSendTriggered()
|
|
|
|
{
|
2017-01-21 03:53:10 +08:00
|
|
|
QString idText = toxId.text().trimmed();
|
|
|
|
ToxId friendId(idText);
|
2014-07-01 02:05:01 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
if (!friendId.isValid()) {
|
2017-01-21 03:53:10 +08:00
|
|
|
friendId = Toxme::lookup(idText); // Try Toxme
|
2017-02-26 19:52:45 +08:00
|
|
|
if (!friendId.isValid()) {
|
2016-08-26 03:57:18 +08:00
|
|
|
GUI::showWarning(tr("Couldn't add friend"),
|
2016-12-28 22:43:11 +08:00
|
|
|
tr("This Tox ID is invalid or does not exist", "Toxme error"));
|
2016-08-26 03:57:18 +08:00
|
|
|
return;
|
2014-11-06 06:27:51 +08:00
|
|
|
}
|
|
|
|
}
|
2016-01-30 06:30:07 +08:00
|
|
|
|
2017-01-21 03:53:10 +08:00
|
|
|
deleteFriendRequest(friendId);
|
2017-02-17 10:14:16 +08:00
|
|
|
if (friendId == Core::getInstance()->getSelfId()) {
|
2016-08-26 03:57:18 +08:00
|
|
|
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"));
|
2017-02-17 10:14:16 +08:00
|
|
|
} else {
|
2017-01-21 03:53:10 +08:00
|
|
|
emit friendRequested(friendId, getMessage());
|
2017-02-17 10:14:16 +08:00
|
|
|
}
|
2016-01-30 06:30:07 +08:00
|
|
|
|
|
|
|
this->toxId.clear();
|
|
|
|
this->message.clear();
|
2014-06-25 04:11:11 +08:00
|
|
|
}
|
2015-03-28 00:43:25 +08:00
|
|
|
|
2017-02-17 10:14:16 +08:00
|
|
|
void AddFriendForm::onImportSendClicked()
|
|
|
|
{
|
|
|
|
for (QString& idText : contactsToImport)
|
|
|
|
{
|
|
|
|
ToxId friendId(idText);
|
|
|
|
|
|
|
|
if (!friendId.isValid())
|
|
|
|
{
|
|
|
|
friendId = Toxme::lookup(idText); // Try Toxme
|
|
|
|
if (!friendId.isValid()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
deleteFriendRequest(friendId);
|
|
|
|
if (friendId == Core::getInstance()->getSelfId()) {
|
|
|
|
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"));
|
|
|
|
} else {
|
|
|
|
emit friendRequested(friendId, getImportMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
contactsToImport.clear();
|
|
|
|
importMessage.clear();
|
|
|
|
retranslateUi(); // Update the importFileLabel
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool checkIsValidId(const QString& id)
|
|
|
|
{
|
|
|
|
static const QRegularExpression dnsIdExpression("^\\S+@\\S+$");
|
|
|
|
return ToxId::isToxId(id) || id.contains(dnsIdExpression);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFriendForm::onImportOpenClicked()
|
|
|
|
{
|
|
|
|
const QString path = QFileDialog::getOpenFileName(tabWidget, tr("Open contact list"));
|
|
|
|
if (path.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QFile contactFile(path);
|
|
|
|
if (!contactFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
|
|
|
GUI::showWarning(tr("Couldn't open file"),
|
|
|
|
tr("Couldn't open the contact file",
|
|
|
|
"Error message when trying to open a contact list file to import"));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
contactsToImport = QString::fromUtf8(contactFile.readAll()).split('\n');
|
|
|
|
QMutableListIterator<QString> it(contactsToImport);
|
|
|
|
qDebug() << "Import list:";
|
|
|
|
while (it.hasNext()) {
|
|
|
|
const QString id = it.value().trimmed();
|
|
|
|
const bool valid = !id.isEmpty() && checkIsValidId(id);
|
|
|
|
if (valid) {
|
|
|
|
it.value() = id;
|
|
|
|
} else {
|
|
|
|
it.remove();
|
|
|
|
}
|
|
|
|
qDebug() << it.next();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (contactsToImport.isEmpty()) {
|
|
|
|
GUI::showWarning(tr("Invalid file"),
|
|
|
|
tr("We couldn't find any contacts to import in this file!"));
|
|
|
|
}
|
|
|
|
|
|
|
|
retranslateUi(); // Update the importFileLabel to show how many contacts we have
|
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void AddFriendForm::onIdChanged(const QString& id)
|
2015-10-10 21:24:23 +08:00
|
|
|
{
|
|
|
|
QString tId = id.trimmed();
|
2017-02-17 10:14:16 +08:00
|
|
|
bool isValidId = tId.isEmpty() || checkIsValidId(tId);
|
2015-10-13 06:32:04 +08:00
|
|
|
|
|
|
|
QString toxIdText(tr("Tox ID", "Tox ID of the person you're sending a friend request to"));
|
2017-02-26 19:52:45 +08:00
|
|
|
QString toxIdComment(
|
|
|
|
tr("either 76 hexadecimal characters or name@example.com", "Tox ID format description"));
|
|
|
|
|
|
|
|
if (isValidId) {
|
|
|
|
toxIdLabel.setText(toxIdText + QStringLiteral(" (") + toxIdComment + QStringLiteral(")"));
|
|
|
|
} else {
|
|
|
|
toxIdLabel.setText(toxIdText + QStringLiteral(" <font color='red'>(") + toxIdComment
|
|
|
|
+ QStringLiteral(")</font>"));
|
2015-10-13 06:32:04 +08:00
|
|
|
}
|
2015-10-10 23:25:24 +08:00
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
toxId.setStyleSheet(isValidId ? QStringLiteral("")
|
|
|
|
: QStringLiteral("QLineEdit { background-color: #FFC1C1; }"));
|
2015-10-13 06:32:04 +08:00
|
|
|
toxId.setToolTip(isValidId ? QStringLiteral("") : tr("Invalid Tox ID format"));
|
2015-10-10 23:25:24 +08:00
|
|
|
|
2015-10-13 06:32:04 +08:00
|
|
|
sendButton.setEnabled(isValidId && !tId.isEmpty());
|
2015-10-10 21:24:23 +08:00
|
|
|
}
|
|
|
|
|
2015-03-28 00:43:25 +08:00
|
|
|
void AddFriendForm::setIdFromClipboard()
|
|
|
|
{
|
|
|
|
QClipboard* clipboard = QApplication::clipboard();
|
|
|
|
QString id = clipboard->text().trimmed();
|
2016-11-09 05:21:08 +08:00
|
|
|
const Core* core = Core::getInstance();
|
2017-02-26 19:52:45 +08:00
|
|
|
if (core->isReady() && !id.isEmpty() && ToxId::isToxId(id) && ToxId(id) != core->getSelfId()) {
|
2016-11-09 05:21:08 +08:00
|
|
|
toxId.setText(id);
|
2015-03-28 00:43:25 +08:00
|
|
|
}
|
|
|
|
}
|
2015-08-21 22:32:00 +08:00
|
|
|
|
2016-12-30 06:14:48 +08:00
|
|
|
void AddFriendForm::deleteFriendRequest(const ToxId& toxId)
|
2016-04-19 15:48:33 +08:00
|
|
|
{
|
|
|
|
int size = Settings::getInstance().getFriendRequestSize();
|
2017-02-26 19:52:45 +08:00
|
|
|
for (int i = 0; i < size; ++i) {
|
2016-04-19 15:48:33 +08:00
|
|
|
Settings::Request request = Settings::getInstance().getFriendRequest(i);
|
2017-02-26 19:52:45 +08:00
|
|
|
if (toxId == ToxId(request.address)) {
|
2016-04-19 15:48:33 +08:00
|
|
|
Settings::getInstance().removeFriendRequest(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-21 05:32:57 +08:00
|
|
|
void AddFriendForm::onFriendRequestAccepted()
|
|
|
|
{
|
2016-02-21 20:46:45 +08:00
|
|
|
QPushButton* acceptButton = static_cast<QPushButton*>(sender());
|
|
|
|
QWidget* friendWidget = acceptButton->parentWidget();
|
2016-02-21 05:32:57 +08:00
|
|
|
int index = requestsLayout->indexOf(friendWidget);
|
2016-03-25 15:45:44 +08:00
|
|
|
removeFriendRequestWidget(friendWidget);
|
2017-02-26 19:52:45 +08:00
|
|
|
Settings::Request request =
|
|
|
|
Settings::getInstance().getFriendRequest(requestsLayout->count() - index - 1);
|
2016-12-30 06:14:48 +08:00
|
|
|
emit friendRequestAccepted(ToxId(request.address).getPublicKey());
|
2016-02-21 05:32:57 +08:00
|
|
|
Settings::getInstance().removeFriendRequest(requestsLayout->count() - index - 1);
|
|
|
|
Settings::getInstance().savePersonal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFriendForm::onFriendRequestRejected()
|
|
|
|
{
|
2016-02-21 20:46:45 +08:00
|
|
|
QPushButton* rejectButton = static_cast<QPushButton*>(sender());
|
|
|
|
QWidget* friendWidget = rejectButton->parentWidget();
|
2016-02-21 05:32:57 +08:00
|
|
|
int index = requestsLayout->indexOf(friendWidget);
|
2016-03-25 15:45:44 +08:00
|
|
|
removeFriendRequestWidget(friendWidget);
|
2016-02-21 05:32:57 +08:00
|
|
|
Settings::getInstance().removeFriendRequest(requestsLayout->count() - index - 1);
|
|
|
|
Settings::getInstance().savePersonal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddFriendForm::onCurrentChanged(int index)
|
|
|
|
{
|
2017-02-26 19:52:45 +08:00
|
|
|
if (index == FriendRequest && Settings::getInstance().getUnreadFriendRequests() != 0) {
|
2016-02-21 05:32:57 +08:00
|
|
|
Settings::getInstance().clearUnreadFriendRequests();
|
|
|
|
Settings::getInstance().savePersonal();
|
|
|
|
emit friendRequestsSeen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-06 03:37:01 +08:00
|
|
|
void AddFriendForm::retranslateUi()
|
|
|
|
{
|
|
|
|
headLabel.setText(tr("Add Friends"));
|
2017-02-17 10:14:16 +08:00
|
|
|
static const QString messageLabelText = tr("Message",
|
|
|
|
"The message you send in friend requests");
|
|
|
|
messageLabel.setText(messageLabelText);
|
|
|
|
importMessageLabel.setText(messageLabelText);
|
|
|
|
importFileButton.setText(tr("Open", "Button to choose a file with a list of contacts to import"));
|
|
|
|
importSendButton.setText(tr("Send friend requests"));
|
2015-06-06 03:37:01 +08:00
|
|
|
sendButton.setText(tr("Send friend request"));
|
2017-02-26 19:52:45 +08:00
|
|
|
message.setPlaceholderText(tr("%1 here! Tox me maybe?", "Default message in friend requests if "
|
|
|
|
"the field is left blank. Write "
|
|
|
|
"something appropriate!")
|
|
|
|
.arg(lastUsername));
|
2017-02-17 10:14:16 +08:00
|
|
|
importMessage.setPlaceholderText(message.placeholderText());
|
|
|
|
|
|
|
|
if (contactsToImport.isEmpty()) {
|
|
|
|
importFileLabel.setText(tr("Import a list of contacts, one Tox ID per line"));
|
|
|
|
} else {
|
|
|
|
importFileLabel.setText(tr("Ready to import %n contact(s), click send to confirm",
|
|
|
|
"Shows the number of contacts we're about to import from a file"
|
|
|
|
" (at least one)", contactsToImport.size()));
|
|
|
|
}
|
2015-10-13 06:32:04 +08:00
|
|
|
|
|
|
|
onIdChanged(toxId.text());
|
2016-02-21 05:32:57 +08:00
|
|
|
|
|
|
|
tabWidget->setTabText(0, tr("Add a friend"));
|
2017-02-17 10:14:16 +08:00
|
|
|
tabWidget->setTabText(1, tr("Import contacts"));
|
|
|
|
tabWidget->setTabText(2, tr("Friend requests"));
|
2016-02-21 05:32:57 +08:00
|
|
|
|
2017-02-17 10:14:16 +08:00
|
|
|
for (QPushButton* acceptButton : acceptButtons) {
|
2016-02-21 05:32:57 +08:00
|
|
|
retranslateAcceptButton(acceptButton);
|
2017-02-17 10:14:16 +08:00
|
|
|
}
|
2016-02-21 05:32:57 +08:00
|
|
|
|
2017-02-17 10:14:16 +08:00
|
|
|
for (QPushButton* rejectButton : rejectButtons) {
|
2016-02-21 05:32:57 +08:00
|
|
|
retranslateRejectButton(rejectButton);
|
2017-02-17 10:14:16 +08:00
|
|
|
}
|
2016-02-21 05:32:57 +08:00
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void AddFriendForm::addFriendRequestWidget(const QString& friendAddress, const QString& message)
|
2016-02-21 05:32:57 +08:00
|
|
|
{
|
|
|
|
QWidget* friendWidget = new QWidget(tabWidget);
|
|
|
|
QHBoxLayout* friendLayout = new QHBoxLayout(friendWidget);
|
|
|
|
QVBoxLayout* horLayout = new QVBoxLayout();
|
|
|
|
horLayout->setMargin(0);
|
|
|
|
friendLayout->addLayout(horLayout);
|
|
|
|
|
2016-02-25 21:40:48 +08:00
|
|
|
CroppingLabel* friendLabel = new CroppingLabel(friendWidget);
|
2016-12-09 10:54:37 +08:00
|
|
|
friendLabel->setTextInteractionFlags(Qt::TextBrowserInteraction);
|
2016-02-21 05:32:57 +08:00
|
|
|
friendLabel->setText("<b>" + friendAddress + "</b>");
|
|
|
|
horLayout->addWidget(friendLabel);
|
|
|
|
|
|
|
|
QLabel* messageLabel = new QLabel(message);
|
2016-12-09 10:54:37 +08:00
|
|
|
// allow to select text, but treat links as plaintext to prevent phishing
|
2017-02-26 19:52:45 +08:00
|
|
|
messageLabel->setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
|
2016-02-26 19:59:03 +08:00
|
|
|
messageLabel->setTextFormat(Qt::PlainText);
|
2016-02-21 05:32:57 +08:00
|
|
|
messageLabel->setWordWrap(true);
|
|
|
|
horLayout->addWidget(messageLabel, 1);
|
|
|
|
|
|
|
|
QPushButton* acceptButton = new QPushButton(friendWidget);
|
2016-03-25 15:45:44 +08:00
|
|
|
acceptButtons.append(acceptButton);
|
2016-02-22 07:29:12 +08:00
|
|
|
connect(acceptButton, &QPushButton::released, this, &AddFriendForm::onFriendRequestAccepted);
|
2016-02-21 05:32:57 +08:00
|
|
|
friendLayout->addWidget(acceptButton);
|
|
|
|
retranslateAcceptButton(acceptButton);
|
|
|
|
|
|
|
|
QPushButton* rejectButton = new QPushButton(friendWidget);
|
2016-03-25 15:45:44 +08:00
|
|
|
rejectButtons.append(rejectButton);
|
2016-02-22 07:29:12 +08:00
|
|
|
connect(rejectButton, &QPushButton::released, this, &AddFriendForm::onFriendRequestRejected);
|
2016-02-21 05:32:57 +08:00
|
|
|
friendLayout->addWidget(rejectButton);
|
|
|
|
retranslateRejectButton(rejectButton);
|
|
|
|
|
|
|
|
requestsLayout->insertWidget(0, friendWidget);
|
|
|
|
}
|
|
|
|
|
2016-03-25 15:45:44 +08:00
|
|
|
void AddFriendForm::removeFriendRequestWidget(QWidget* friendWidget)
|
|
|
|
{
|
|
|
|
int index = requestsLayout->indexOf(friendWidget);
|
|
|
|
requestsLayout->removeWidget(friendWidget);
|
|
|
|
acceptButtons.removeAt(index);
|
|
|
|
rejectButtons.removeAt(index);
|
|
|
|
friendWidget->deleteLater();
|
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void AddFriendForm::retranslateAcceptButton(QPushButton* acceptButton)
|
2016-02-21 05:32:57 +08:00
|
|
|
{
|
|
|
|
acceptButton->setText(tr("Accept"));
|
|
|
|
}
|
|
|
|
|
2017-02-26 19:52:45 +08:00
|
|
|
void AddFriendForm::retranslateRejectButton(QPushButton* rejectButton)
|
2016-02-21 05:32:57 +08:00
|
|
|
{
|
|
|
|
rejectButton->setText(tr("Reject"));
|
2015-08-22 00:36:59 +08:00
|
|
|
}
|