mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor(friendwidget): Add using const
This commit is contained in:
parent
eb13908926
commit
c4baff4b04
|
@ -100,8 +100,8 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
||||||
QAction* openChatWindow = nullptr;
|
QAction* openChatWindow = nullptr;
|
||||||
QAction* removeChatWindow = nullptr;
|
QAction* removeChatWindow = nullptr;
|
||||||
|
|
||||||
uint32_t friendId = frnd->getFriendId();
|
const uint32_t friendId = frnd->getFriendId();
|
||||||
ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
|
const ContentDialog* contentDialog = ContentDialog::getFriendDialog(friendId);
|
||||||
|
|
||||||
if (!contentDialog || contentDialog->chatroomWidgetCount() > 1) {
|
if (!contentDialog || contentDialog->chatroomWidgetCount() > 1) {
|
||||||
openChatWindow = menu.addAction(tr("Open chat in new window"));
|
openChatWindow = menu.addAction(tr("Open chat in new window"));
|
||||||
|
@ -115,31 +115,30 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
||||||
QMenu* inviteMenu = menu.addMenu(tr("Invite to group",
|
QMenu* inviteMenu = menu.addMenu(tr("Invite to group",
|
||||||
"Menu to invite a friend to a groupchat"));
|
"Menu to invite a friend to a groupchat"));
|
||||||
inviteMenu->setEnabled(frnd->getStatus() != Status::Offline);
|
inviteMenu->setEnabled(frnd->getStatus() != Status::Offline);
|
||||||
QAction* newGroupAction = inviteMenu->addAction(tr("To new group"));
|
const QAction* newGroupAction = inviteMenu->addAction(tr("To new group"));
|
||||||
inviteMenu->addSeparator();
|
inviteMenu->addSeparator();
|
||||||
QMap<QAction*, Group*> groupActions;
|
QMap<const QAction*, const Group*> groupActions;
|
||||||
|
|
||||||
for (Group* group : GroupList::getAllGroups()) {
|
for (const Group* group : GroupList::getAllGroups()) {
|
||||||
int maxNameLen = 30;
|
const int maxNameLen = 30;
|
||||||
QString name = group->getGroupWidget()->getName();
|
QString name = group->getName();
|
||||||
if (name.length() > maxNameLen) {
|
if (name.length() > maxNameLen) {
|
||||||
name = name.left(maxNameLen).trimmed() + "..";
|
name = name.left(maxNameLen).trimmed() + "..";
|
||||||
}
|
}
|
||||||
QAction* groupAction = inviteMenu->addAction(tr("Invite to group '%1'").arg(name));
|
const QAction* groupAction = inviteMenu->addAction(tr("Invite to group '%1'").arg(name));
|
||||||
groupActions[groupAction] = group;
|
groupActions[groupAction] = group;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Settings& s = Settings::getInstance();
|
const Settings& s = Settings::getInstance();
|
||||||
int circleId = s.getFriendCircleID(frnd->getPublicKey());
|
const int circleId = s.getFriendCircleID(frnd->getPublicKey());
|
||||||
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
|
CircleWidget* circleWidget = CircleWidget::getFromID(circleId);
|
||||||
|
|
||||||
QWidget* w = circleWidget ? circleWidget : static_cast<QWidget*>(this);
|
QWidget* w = circleWidget ? circleWidget : static_cast<QWidget*>(this);
|
||||||
FriendListWidget* friendList = qobject_cast<FriendListWidget*>(w->parentWidget());
|
FriendListWidget* friendList = qobject_cast<FriendListWidget*>(w->parentWidget());
|
||||||
|
|
||||||
QMenu* circleMenu = menu.addMenu(tr("Move to circle...",
|
QMenu* circleMenu = menu.addMenu(tr("Move to circle...",
|
||||||
"Menu to move a friend into a different circle"));
|
"Menu to move a friend into a different circle"));
|
||||||
|
|
||||||
QAction* newCircleAction = circleMenu->addAction(tr("To new circle"));
|
const QAction* newCircleAction = circleMenu->addAction(tr("To new circle"));
|
||||||
|
|
||||||
QAction* removeCircleAction = nullptr;
|
QAction* removeCircleAction = nullptr;
|
||||||
if (circleId != -1) {
|
if (circleId != -1) {
|
||||||
|
@ -172,13 +171,13 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
||||||
|
|
||||||
circleMenu->addActions(circleActionList);
|
circleMenu->addActions(circleActionList);
|
||||||
|
|
||||||
QAction* setAlias = menu.addAction(tr("Set alias..."));
|
const QAction* setAlias = menu.addAction(tr("Set alias..."));
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
QAction* autoAccept = menu.addAction(tr("Auto accept files from this friend",
|
QAction* autoAccept = menu.addAction(tr("Auto accept files from this friend",
|
||||||
"context menu entry"));
|
"context menu entry"));
|
||||||
ToxPk id = frnd->getPublicKey();
|
const ToxPk id = frnd->getPublicKey();
|
||||||
QString dir = s.getAutoAcceptDir(id);
|
const QString dir = s.getAutoAcceptDir(id);
|
||||||
autoAccept->setCheckable(true);
|
autoAccept->setCheckable(true);
|
||||||
autoAccept->setChecked(!dir.isEmpty());
|
autoAccept->setChecked(!dir.isEmpty());
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
|
@ -191,9 +190,9 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.addSeparator();
|
menu.addSeparator();
|
||||||
QAction* aboutWindow = menu.addAction(tr("Show details"));
|
const QAction* aboutWindow = menu.addAction(tr("Show details"));
|
||||||
|
|
||||||
QPoint pos = event->globalPos();
|
const QPoint pos = event->globalPos();
|
||||||
QAction* selectedItem = menu.exec(pos);
|
QAction* selectedItem = menu.exec(pos);
|
||||||
|
|
||||||
removeEventFilter(this);
|
removeEventFilter(this);
|
||||||
|
@ -218,13 +217,11 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
||||||
} else if (selectedItem == autoAccept) {
|
} else if (selectedItem == autoAccept) {
|
||||||
if (!autoAccept->isChecked()) {
|
if (!autoAccept->isChecked()) {
|
||||||
qDebug() << "not checked";
|
qDebug() << "not checked";
|
||||||
dir = QDir::homePath();
|
|
||||||
autoAccept->setChecked(false);
|
autoAccept->setChecked(false);
|
||||||
Settings::getInstance().setAutoAcceptDir(id, "");
|
Settings::getInstance().setAutoAcceptDir(id, "");
|
||||||
} else if (autoAccept->isChecked()) {
|
} else if (autoAccept->isChecked()) {
|
||||||
dir = QFileDialog::getExistingDirectory(Q_NULLPTR,
|
const QString dir = QFileDialog::getExistingDirectory(
|
||||||
tr("Choose an auto accept directory", "popup title"),
|
Q_NULLPTR, tr("Choose an auto accept directory", "popup title"), dir);
|
||||||
dir);
|
|
||||||
|
|
||||||
autoAccept->setChecked(true);
|
autoAccept->setChecked(true);
|
||||||
qDebug() << "Setting auto accept dir for" << friendId << "to" << dir;
|
qDebug() << "Setting auto accept dir for" << friendId << "to" << dir;
|
||||||
|
@ -235,24 +232,27 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
||||||
AboutUser* aboutUser = new AboutUser(f, Widget::getInstance());
|
AboutUser* aboutUser = new AboutUser(f, Widget::getInstance());
|
||||||
aboutUser->show();
|
aboutUser->show();
|
||||||
} else if (selectedItem == newGroupAction) {
|
} else if (selectedItem == newGroupAction) {
|
||||||
int groupId = Core::getInstance()->createGroup();
|
const int groupId = Core::getInstance()->createGroup();
|
||||||
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
Core::getInstance()->groupInviteFriend(friendId, groupId);
|
||||||
} else if (selectedItem == newCircleAction) {
|
} else if (selectedItem == newCircleAction) {
|
||||||
if (circleWidget != nullptr)
|
if (circleWidget != nullptr) {
|
||||||
circleWidget->updateStatus();
|
circleWidget->updateStatus();
|
||||||
|
}
|
||||||
|
|
||||||
if (friendList != nullptr)
|
if (friendList != nullptr) {
|
||||||
friendList->addCircleWidget(this);
|
friendList->addCircleWidget(this);
|
||||||
else
|
} else {
|
||||||
Settings::getInstance().setFriendCircleID(id, Settings::getInstance().addCircle());
|
Settings::getInstance().setFriendCircleID(id, Settings::getInstance().addCircle());
|
||||||
|
}
|
||||||
} else if (groupActions.contains(selectedItem)) {
|
} else if (groupActions.contains(selectedItem)) {
|
||||||
Group* group = groupActions[selectedItem];
|
const Group* group = groupActions[selectedItem];
|
||||||
Core::getInstance()->groupInviteFriend(friendId, group->getGroupId());
|
Core::getInstance()->groupInviteFriend(friendId, group->getGroupId());
|
||||||
} else if (removeCircleAction != nullptr && selectedItem == removeCircleAction) {
|
} else if (removeCircleAction != nullptr && selectedItem == removeCircleAction) {
|
||||||
if (friendList)
|
if (friendList) {
|
||||||
friendList->moveWidget(this, frnd->getStatus(), true);
|
friendList->moveWidget(this, frnd->getStatus(), true);
|
||||||
else
|
} else {
|
||||||
Settings::getInstance().setFriendCircleID(id, -1);
|
Settings::getInstance().setFriendCircleID(id, -1);
|
||||||
|
}
|
||||||
|
|
||||||
if (circleWidget) {
|
if (circleWidget) {
|
||||||
circleWidget->updateStatus();
|
circleWidget->updateStatus();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user