From e91846e821fd4a29b8e71e810ee35d4e5b06a1cb Mon Sep 17 00:00:00 2001 From: "Tux3 / Mlkj / !Lev.uXFMLA" Date: Thu, 11 Sep 2014 13:40:27 +0200 Subject: [PATCH] Fix #205 --- core.cpp | 8 ++++++++ core.h | 1 + widget/form/addfriendform.cpp | 8 +++++++- widget/widget.cpp | 3 ++- 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core.cpp b/core.cpp index fe32ff255..54bb1520a 100644 --- a/core.cpp +++ b/core.cpp @@ -701,6 +701,14 @@ void Core::setUsername(const QString& username) } } +QString Core::getSelfId() +{ + uint8_t friendAddress[TOX_FRIEND_ADDRESS_SIZE]; + tox_get_address(tox, friendAddress); + + return CFriendAddress::toString(friendAddress); +} + QString Core::getStatusMessage() { int size = tox_get_self_status_message_size(tox); diff --git a/core.h b/core.h index e22bd183d..af9fab8a3 100644 --- a/core.h +++ b/core.h @@ -127,6 +127,7 @@ public: QString getUsername(); QString getStatusMessage(); + QString getSelfId(); void increaseVideoBusyness(); void decreaseVideoBusyness(); diff --git a/widget/form/addfriendform.cpp b/widget/form/addfriendform.cpp index 9d09e0682..89bb0935d 100644 --- a/widget/form/addfriendform.cpp +++ b/widget/form/addfriendform.cpp @@ -19,6 +19,8 @@ #include #include #include +#include "widget/widget.h" +#include "core.h" #define TOX_ID_LENGTH 2*TOX_FRIEND_ADDRESS_SIZE @@ -74,6 +76,7 @@ bool AddFriendForm::isToxId(const QString &value) const void AddFriendForm::showWarning(const QString &message) const { QMessageBox warning(main); + warning.setWindowTitle("Tox"); warning.setText(message); warning.setIcon(QMessageBox::Warning); warning.exec(); @@ -92,7 +95,10 @@ void AddFriendForm::onSendTriggered() if (id.isEmpty()) { showWarning(tr("Please fill in a valid Tox ID","Tox ID of the friend you're sending a friend request to")); } else if (isToxId(id)) { - emit friendRequested(id, getMessage()); + if (id.toUpper() == Widget::getInstance()->getCore()->getSelfId().toUpper()) + showWarning(tr("You can't add yourself as a friend !","When trying to add your own Tox ID as friend")); + else + emit friendRequested(id, getMessage()); this->toxId.setText(""); this->message.setText(""); } else { diff --git a/widget/widget.cpp b/widget/widget.cpp index 7be90b784..89237158e 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -404,7 +404,8 @@ void Widget::setStatusMessage(const QString &statusMessage) void Widget::addFriend(int friendId, const QString &userId) { - qDebug() << "Adding friend with id "+userId; + + qDebug() << "Widget: Adding friend with id "+userId; Friend* newfriend = FriendList::addFriend(friendId, userId); QLayout* layout = contactListWidget->getFriendLayout(Status::Offline); layout->addWidget(newfriend->widget);