Browse Source

refactor: remove getInstance from AddFriendForm

reviewable/pr6157/r3
sudden6 5 years ago
parent
commit
19f4a6c4e0
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
  1. 11
      src/widget/form/addfriendform.cpp
  2. 4
      src/widget/form/addfriendform.h
  3. 2
      src/widget/widget.cpp

11
src/widget/form/addfriendform.cpp

@ -61,10 +61,12 @@ namespace @@ -61,10 +61,12 @@ namespace
* @brief Cached username so we can retranslate the invite message
*/
AddFriendForm::AddFriendForm()
AddFriendForm::AddFriendForm(ToxId _ownId)
: ownId{_ownId}
{
tabWidget = new QTabWidget();
main = new QWidget(tabWidget), head = new QWidget();
main = new QWidget(tabWidget);
head = new QWidget();
QFont bold;
bold.setBold(true);
headLabel.setFont(bold);
@ -206,7 +208,7 @@ void AddFriendForm::addFriend(const QString& idText) @@ -206,7 +208,7 @@ void AddFriendForm::addFriend(const QString& idText)
}
deleteFriendRequest(friendId);
if (friendId == Core::getInstance()->getSelfId()) {
if (friendId == ownId) {
GUI::showWarning(tr("Couldn't add friend"),
//: When trying to add your own Tox ID as friend
tr("You can't add yourself as a friend!"));
@ -301,8 +303,7 @@ void AddFriendForm::setIdFromClipboard() @@ -301,8 +303,7 @@ void AddFriendForm::setIdFromClipboard()
const QClipboard* clipboard = QApplication::clipboard();
const QString trimmedId = clipboard->text().trimmed();
const QString strippedId = getToxId(trimmedId);
const Core* core = Core::getInstance();
const bool isSelf = ToxId::isToxId(strippedId) && ToxId(strippedId) != core->getSelfId();
const bool isSelf = ToxId::isToxId(strippedId) && ToxId(strippedId) != ownId;
if (!strippedId.isEmpty() && ToxId::isToxId(strippedId) && isSelf) {
toxId.setText(trimmedId);
}

4
src/widget/form/addfriendform.h

@ -45,7 +45,7 @@ public: @@ -45,7 +45,7 @@ public:
FriendRequest = 2
};
AddFriendForm();
AddFriendForm(ToxId _ownId);
AddFriendForm(const AddFriendForm&) = delete;
AddFriendForm& operator=(const AddFriendForm&) = delete;
~AddFriendForm();
@ -111,4 +111,6 @@ private: @@ -111,4 +111,6 @@ private:
QList<QPushButton*> acceptButtons;
QList<QPushButton*> rejectButtons;
QList<QString> contactsToImport;
ToxId ownId;
};

2
src/widget/widget.cpp

@ -275,7 +275,7 @@ void Widget::init() @@ -275,7 +275,7 @@ void Widget::init()
Style::setThemeColor(settings.getThemeColor());
filesForm = new FilesForm();
addFriendForm = new AddFriendForm;
addFriendForm = new AddFriendForm(core->getSelfId());
groupInviteForm = new GroupInviteForm;
core = &profile.getCore();

Loading…
Cancel
Save