diff options
author | tandunn <tandunn@umich.edu> | 2020-12-19 01:36:29 +0300 |
---|---|---|
committer | Robert Adam <krzmbrzl@gmail.com> | 2020-12-20 11:14:11 +0300 |
commit | ba27c8f8bbed711c1ddca906fc8b206077ef7616 (patch) | |
tree | e0cbdc4439627e7b4a25edd72e6f8d083943db97 /src/mumble/UserLocalNicknameDialog.cpp | |
parent | 675c04632ce1791e4d205b30003462f92aca5360 (diff) |
FEAT(client): Add possibility to set nickname
As requested in #3967 this commit implements the ability to set
nicknames for other users when connected to the same server. The change
is added to the client database by the user id for persistence. In order
to set a nickname, a user can right click on that user and click Set
Nickname. This opens a window where the user can enter the new nickname.
If the text field is cleared, no nickname is displayed.
Implements #3967
Diffstat (limited to 'src/mumble/UserLocalNicknameDialog.cpp')
-rw-r--r-- | src/mumble/UserLocalNicknameDialog.cpp | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/src/mumble/UserLocalNicknameDialog.cpp b/src/mumble/UserLocalNicknameDialog.cpp new file mode 100644 index 000000000..afb43bc88 --- /dev/null +++ b/src/mumble/UserLocalNicknameDialog.cpp @@ -0,0 +1,93 @@ +// Copyright 2020 The Mumble Developers. All rights reserved. +// Use of this source code is governed by a BSD-style license +// that can be found in the LICENSE file at the root of the +// Mumble source tree or at <https://www.mumble.info/LICENSE>. + +#include "UserLocalNicknameDialog.h" +#include "ClientUser.h" +#include "Database.h" +#include "MainWindow.h" + +#include <QtGui/QCloseEvent> +#include <QtWidgets/QPushButton> + +// We define a global macro called 'g'. This can lead to issues when included code uses 'g' as a type or parameter name +// (like protobuf 3.7 does). As such, for now, we have to make this our last include. +#include "Global.h" + +UserLocalNicknameDialog::UserLocalNicknameDialog( + unsigned int sessionId, + std::unordered_map< unsigned int, std::unique_ptr< UserLocalNicknameDialog > > &qmUserNicknameTracker) + : QDialog(nullptr), m_clientSession(sessionId), m_qmUserNicknameTracker(qmUserNicknameTracker) { + setupUi(this); + + qleUserLocalNickname->setFocus(); + + qleUserLocalNickname->setAccessibleName(tr("User nickname")); + + ClientUser *user = ClientUser::get(sessionId); + if (!user) { + UserLocalNicknameDialog::close(); + } else { + QString title = tr("Adjusting local nickname for %1").arg(user->qsName); + setWindowTitle(title); + qleUserLocalNickname->setText(user->getLocalNickname()); + m_originalNickname = qleUserLocalNickname->text(); + } + + if (g.mw && g.mw->windowFlags() & Qt::WindowStaysOnTopHint) { + // If the main window is set to always be on top of other windows, we should make the + // nickname dialog behave the same in order for it to not get hidden behind the main window. + setWindowFlags(Qt::WindowStaysOnTopHint); + } +} + +void UserLocalNicknameDialog::closeEvent(QCloseEvent *event) { + m_qmUserNicknameTracker.erase(m_clientSession); + event->accept(); +} + +void UserLocalNicknameDialog::present( + unsigned int sessionId, + std::unordered_map< unsigned int, std::unique_ptr< UserLocalNicknameDialog > > &qmUserNicknameTracker) { + if (qmUserNicknameTracker.find(sessionId) != qmUserNicknameTracker.end()) { + qmUserNicknameTracker.at(sessionId)->show(); + qmUserNicknameTracker.at(sessionId)->raise(); + } else { + std::unique_ptr< UserLocalNicknameDialog > userNickname = + std::make_unique< UserLocalNicknameDialog >(sessionId, qmUserNicknameTracker); + userNickname->show(); + qmUserNicknameTracker.insert(std::make_pair(sessionId, std::move(userNickname))); + } +} + +void UserLocalNicknameDialog::on_qleUserLocalNickname_textChanged(const QString &text) { + ClientUser *user = ClientUser::get(m_clientSession); + if (user) { + user->setLocalNickname(text); + } +} + +void UserLocalNicknameDialog::on_qbbUserLocalNickname_clicked(QAbstractButton *button) { + if (button == qbbUserLocalNickname->button(QDialogButtonBox::Reset)) { + qleUserLocalNickname->setText(m_originalNickname); + } else if (button == qbbUserLocalNickname->button(QDialogButtonBox::Ok)) { + ClientUser *user = ClientUser::get(m_clientSession); + if (user) { + if (!user->qsHash.isEmpty()) { + g.db->setUserLocalNickname(user->qsHash, user->getLocalNickname()); + } else { + g.mw->logChangeNotPermanent(QObject::tr("Local Nickname Adjustment..."), user); + } + } + UserLocalNicknameDialog::close(); + } else if (button == qbbUserLocalNickname->button(QDialogButtonBox::Cancel)) { + qleUserLocalNickname->setText(m_originalNickname); + UserLocalNicknameDialog::close(); + } +} + +void UserLocalNicknameDialog::reject() { + m_qmUserNicknameTracker.erase(m_clientSession); + UserLocalNicknameDialog::close(); +} |