blob: 14a9489ad2c15e1ec3287d70e82909bebd60e833 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
// Copyright 2020-2021 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 "Global.h"
#include <QtGui/QCloseEvent>
#include <QtWidgets/QPushButton>
UserLocalNicknameDialog::UserLocalNicknameDialog(
unsigned int sessionId,
std::unordered_map< unsigned int, NicknameDialogPtr > &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 (Global::get().mw && Global::get().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, NicknameDialogPtr > &qmUserNicknameTracker) {
if (qmUserNicknameTracker.find(sessionId) != qmUserNicknameTracker.end()) {
qmUserNicknameTracker.at(sessionId)->show();
qmUserNicknameTracker.at(sessionId)->raise();
} else {
// Make sure to use the custom deleter for QObjects that calls deleteLater() on them instead of using
// delete directly as the latter can lead to segmentation faults.
NicknameDialogPtr userNickname(new UserLocalNicknameDialog(sessionId, qmUserNicknameTracker), deleteQObject);
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()) {
Global::get().db->setUserLocalNickname(user->qsHash, user->getLocalNickname());
} else {
Global::get().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();
}
|