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

View File

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