1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor: Use model in chatroom widgets

This commit is contained in:
Diadlo 2019-06-19 12:34:08 +03:00
parent 0b9b538601
commit 678fc51c1b
2 changed files with 9 additions and 30 deletions

View File

@ -18,7 +18,6 @@
#include "friendwidget.h"
#include "circlewidget.h"
#include "contentdialog.h"
#include "friendlistwidget.h"
#include "groupwidget.h"
#include "maskablepixmapwidget.h"
@ -32,7 +31,6 @@
#include "src/model/status.h"
#include "src/persistence/settings.h"
#include "src/widget/about/aboutfriendform.h"
#include "src/widget/contentdialogmanager.h"
#include "src/widget/form/chatform.h"
#include "src/widget/style.h"
#include "src/widget/tool/croppinglabel.h"
@ -105,18 +103,12 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
QMenu menu;
const auto frnd = chatroom->getFriend();
const auto friendPk = frnd->getPublicKey();
const auto contentDialog = ContentDialogManager::getInstance()->getFriendDialog(friendPk);
// TODO: move to model
if (!contentDialog || contentDialog->chatroomCount() > 1) {
if (chatroom->possibleToOpenInNewWindow()) {
const auto openChatWindow = menu.addAction(tr("Open chat in new window"));
connect(openChatWindow, &QAction::triggered, [=]() { emit newWindowOpened(this); });
}
// TODO: move to model
if (contentDialog && contentDialog->hasContact(friendPk)) {
if (chatroom->canBeRemovedFromWindow()) {
const auto removeChatWindow = menu.addAction(tr("Remove chat from this window"));
connect(removeChatWindow, &QAction::triggered, this, &FriendWidget::removeChatWindow);
}
@ -140,7 +132,6 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
auto circleMenu =
menu.addMenu(tr("Move to circle...", "Menu to move a friend into a different circle"));
const auto pk = frnd->getPublicKey();
const auto newCircleAction = circleMenu->addAction(tr("To new circle"));
connect(newCircleAction, &QAction::triggered, this, &FriendWidget::moveToNewCircle);
@ -170,8 +161,8 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
connect(autoAccept, &QAction::triggered, this, &FriendWidget::changeAutoAccept);
menu.addSeparator();
// TODO: move to model
if (!contentDialog || !contentDialog->hasContact(friendPk)) {
if (chatroom->friendCanBeRemoved()) {
const auto friendPk = chatroom->getFriend()->getPublicKey();
const auto removeAction =
menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
connect(removeAction, &QAction::triggered, this, [=]() { emit removeFriend(friendPk); },
@ -194,10 +185,7 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
void FriendWidget::removeChatWindow()
{
const auto frnd = chatroom->getFriend();
const auto friendPk = frnd->getPublicKey();
ContentDialog* contentDialog = ContentDialogManager::getInstance()->getFriendDialog(friendPk);
contentDialog->removeFriend(friendPk);
chatroom->removeFriendFromDialogs();
}
namespace {

View File

@ -27,7 +27,6 @@
#include <QMimeData>
#include <QPalette>
#include "contentdialog.h"
#include "maskablepixmapwidget.h"
#include "form/groupchatform.h"
#include "src/core/core.h"
@ -36,7 +35,6 @@
#include "src/model/group.h"
#include "src/model/status.h"
#include "src/grouplist.h"
#include "src/widget/contentdialogmanager.h"
#include "src/widget/friendwidget.h"
#include "src/widget/style.h"
#include "src/widget/translator.h"
@ -86,17 +84,12 @@ void GroupWidget::contextMenuEvent(QContextMenuEvent* event)
QMenu menu(this);
QAction* openChatWindow = nullptr;
QAction* removeChatWindow = nullptr;
// TODO: Move to model
ContentDialog* contentDialog = ContentDialogManager::getInstance()->getGroupDialog(groupId);
const bool notAlone = contentDialog != nullptr && contentDialog->chatroomCount() > 1;
if (contentDialog == nullptr || notAlone) {
if (chatroom->possibleToOpenInNewWindow() ) {
openChatWindow = menu.addAction(tr("Open chat in new window"));
}
if (contentDialog && contentDialog->hasContact(groupId)) {
QAction* removeChatWindow = nullptr;
if (chatroom->canBeRemovedFromWindow()) {
removeChatWindow = menu.addAction(tr("Remove chat from this window"));
}
@ -122,9 +115,7 @@ void GroupWidget::contextMenuEvent(QContextMenuEvent* event)
} else if (selectedItem == openChatWindow) {
emit newWindowOpened(this);
} else if (selectedItem == removeChatWindow) {
// TODO: move to model
ContentDialog* contentDialog = ContentDialogManager::getInstance()->getGroupDialog(groupId);
contentDialog->removeGroup(groupId);
chatroom->removeGroupFromDialogs();
} else if (selectedItem == setTitle) {
editName();
}