mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Create interfaces for ContentDialog and ContenDialogManager
This commit is contained in:
parent
c2bdcdf6c2
commit
ac36ed8180
|
@ -336,6 +336,7 @@ set(${PROJECT_NAME}_SOURCES
|
|||
src/model/profile/iprofileinfo.h
|
||||
src/model/profile/profileinfo.cpp
|
||||
src/model/profile/profileinfo.h
|
||||
src/model/dialogs/idialogs.h
|
||||
src/net/bootstrapnodeupdater.cpp
|
||||
src/net/bootstrapnodeupdater.h
|
||||
src/net/avatarbroadcaster.cpp
|
||||
|
|
39
src/model/dialogs/idialogs.h
Normal file
39
src/model/dialogs/idialogs.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
Copyright © 2019 by The qTox Project Contributors
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
qTox is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
qTox is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef I_DIALOGS_H
|
||||
#define I_DIALOGS_H
|
||||
|
||||
class ContactId;
|
||||
class GroupId;
|
||||
class ToxPk;
|
||||
|
||||
class IDialogs
|
||||
{
|
||||
public:
|
||||
virtual bool hasContact(const ContactId& contactId) const = 0;
|
||||
virtual bool isContactActive(const ContactId& contactId) const = 0;
|
||||
|
||||
virtual void removeFriend(const ToxPk& friendPk) = 0;
|
||||
virtual void removeGroup(const GroupId& groupId) = 0;
|
||||
|
||||
virtual int chatroomCount() const = 0;
|
||||
};
|
||||
|
||||
#endif // I_DIALOGS_H
|
35
src/model/dialogs/idialogsmanager.h
Normal file
35
src/model/dialogs/idialogsmanager.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
Copyright © 2019 by The qTox Project Contributors
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
qTox is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
qTox is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with qTox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef I_DIALOGS_MANAGER
|
||||
#define I_DIALOGS_MANAGER
|
||||
|
||||
#include "idialogs.h"
|
||||
|
||||
class GroupId;
|
||||
class ToxPk;
|
||||
|
||||
class IDialogsManager
|
||||
{
|
||||
public:
|
||||
virtual IDialogs* getFriendDialogs(const ToxPk& friendPk) const = 0;
|
||||
virtual IDialogs* getGroupDialogs(const GroupId& groupId) const = 0;
|
||||
};
|
||||
|
||||
#endif // I_DIALOGS_MANAGER
|
|
@ -202,7 +202,7 @@ void ContentDialog::removeFriend(const ToxPk& friendPk)
|
|||
|
||||
chatroomWidget->deleteLater();
|
||||
|
||||
if (chatroomWidgetCount() == 0) {
|
||||
if (chatroomCount() == 0) {
|
||||
contentLayout->clear();
|
||||
activeChatroomWidget = nullptr;
|
||||
deleteLater();
|
||||
|
@ -226,7 +226,7 @@ void ContentDialog::removeGroup(const GroupId& groupId)
|
|||
groupLayout.removeSortedWidget(chatroomWidget);
|
||||
chatroomWidget->deleteLater();
|
||||
|
||||
if (chatroomWidgetCount() == 0) {
|
||||
if (chatroomCount() == 0) {
|
||||
contentLayout->clear();
|
||||
activeChatroomWidget = nullptr;
|
||||
deleteLater();
|
||||
|
@ -246,7 +246,7 @@ void ContentDialog::closeIfEmpty()
|
|||
}
|
||||
}
|
||||
|
||||
int ContentDialog::chatroomWidgetCount() const
|
||||
int ContentDialog::chatroomCount() const
|
||||
{
|
||||
return friendLayout->friendTotalCount() + groupLayout.getLayout()->count();
|
||||
}
|
||||
|
@ -469,7 +469,7 @@ void ContentDialog::dragEnterEvent(QDragEnterEvent* event)
|
|||
ToxPk friendId = contact->getPublicKey();
|
||||
|
||||
// If friend is already in a dialog then you can't drop friend where it already is.
|
||||
if (!hasContactWidget(friendId)) {
|
||||
if (!hasContact(friendId)) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
} else if (group) {
|
||||
|
@ -480,7 +480,7 @@ void ContentDialog::dragEnterEvent(QDragEnterEvent* event)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!hasContactWidget(groupId)) {
|
||||
if (!hasContact(groupId)) {
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
}
|
||||
|
@ -586,11 +586,6 @@ void ContentDialog::activate(GenericChatroomWidget* widget)
|
|||
updateTitleAndStatusIcon();
|
||||
}
|
||||
|
||||
bool ContentDialog::containsContact(const ContactId& contactId) const
|
||||
{
|
||||
return contactWidgets.contains(contactId);
|
||||
}
|
||||
|
||||
void ContentDialog::updateFriendStatus(const ToxPk& friendPk, Status::Status status)
|
||||
{
|
||||
auto widget = qobject_cast<FriendWidget*>(contactWidgets.value(friendPk));
|
||||
|
@ -605,7 +600,7 @@ void ContentDialog::updateContactStatusLight(const ContactId& contactId)
|
|||
}
|
||||
}
|
||||
|
||||
bool ContentDialog::isContactWidgetActive(const ContactId& contactId)
|
||||
bool ContentDialog::isContactActive(const ContactId& contactId) const
|
||||
{
|
||||
auto widget = contactWidgets.value(contactId);
|
||||
if (widget == nullptr) {
|
||||
|
@ -674,7 +669,7 @@ void ContentDialog::saveSplitterState()
|
|||
Settings::getInstance().setDialogSplitterState(splitter->saveState());
|
||||
}
|
||||
|
||||
bool ContentDialog::hasContactWidget(const ContactId& contactId) const
|
||||
bool ContentDialog::hasContact(const ContactId& contactId) const
|
||||
{
|
||||
return contactWidgets.contains(contactId);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright © 2015-2018 by The qTox Project Contributors
|
||||
Copyright © 2015-2019 by The qTox Project Contributors
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
|||
#ifndef CONTENTDIALOG_H
|
||||
#define CONTENTDIALOG_H
|
||||
|
||||
#include "src/model/dialogs/idialogs.h"
|
||||
#include "src/widget/genericchatitemlayout.h"
|
||||
#include "src/widget/tool/activatedialog.h"
|
||||
#include "src/model/status.h"
|
||||
|
@ -27,14 +28,10 @@
|
|||
#include "src/core/toxpk.h"
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
|
||||
template <typename K, typename V>
|
||||
class QHash;
|
||||
template <typename T>
|
||||
class QSet;
|
||||
|
||||
class ContentDialog;
|
||||
class ContentLayout;
|
||||
class Friend;
|
||||
class FriendChatroom;
|
||||
|
@ -47,11 +44,8 @@ class GroupChatroom;
|
|||
class GroupWidget;
|
||||
class QCloseEvent;
|
||||
class QSplitter;
|
||||
class QVBoxLayout;
|
||||
|
||||
using ContactInfo = std::tuple<ContentDialog*, GenericChatroomWidget*>;
|
||||
|
||||
class ContentDialog : public ActivateDialog
|
||||
class ContentDialog : public ActivateDialog, public IDialogs
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -60,9 +54,9 @@ public:
|
|||
|
||||
FriendWidget* addFriend(std::shared_ptr<FriendChatroom> chatroom, GenericChatForm* form);
|
||||
GroupWidget* addGroup(std::shared_ptr<GroupChatroom> chatroom, GenericChatForm* form);
|
||||
void removeFriend(const ToxPk& friendPk);
|
||||
void removeGroup(const GroupId& groupId);
|
||||
int chatroomWidgetCount() const;
|
||||
void removeFriend(const ToxPk& friendPk) override;
|
||||
void removeGroup(const GroupId& groupId) override;
|
||||
int chatroomCount() const override;
|
||||
void ensureSplitterVisible();
|
||||
void updateTitleAndStatusIcon();
|
||||
|
||||
|
@ -73,12 +67,12 @@ public:
|
|||
void addFriendWidget(FriendWidget* widget, Status::Status status);
|
||||
bool isActiveWidget(GenericChatroomWidget* widget);
|
||||
|
||||
bool hasContactWidget(const ContactId& contactId) const;
|
||||
bool hasContact(const ContactId& contactId) const override;
|
||||
bool isContactActive(const ContactId& contactId) const override;
|
||||
|
||||
void focusContact(const ContactId& friendPk);
|
||||
bool containsContact(const ContactId& friendPk) const;
|
||||
void updateFriendStatus(const ToxPk& friendPk, Status::Status status);
|
||||
void updateContactStatusLight(const ContactId& contactId);
|
||||
bool isContactWidgetActive(const ContactId& contactId);
|
||||
|
||||
void setStatusMessage(const ToxPk& friendPk, const QString& message);
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ bool ContentDialogManager::contactWidgetExists(const ContactId& contactId)
|
|||
return false;
|
||||
}
|
||||
|
||||
return dialog->containsContact(contactId);
|
||||
return dialog->hasContact(contactId);
|
||||
}
|
||||
|
||||
FriendWidget* ContentDialogManager::addFriendToDialog(ContentDialog* dialog,
|
||||
|
@ -109,7 +109,7 @@ void ContentDialogManager::updateFriendStatus(const ToxPk& friendPk)
|
|||
}
|
||||
|
||||
dialog->updateContactStatusLight(friendPk);
|
||||
if (dialog->isContactWidgetActive(friendPk)) {
|
||||
if (dialog->isContactActive(friendPk)) {
|
||||
dialog->updateTitleAndStatusIcon();
|
||||
}
|
||||
|
||||
|
@ -125,19 +125,19 @@ void ContentDialogManager::updateGroupStatus(const GroupId& groupId)
|
|||
}
|
||||
|
||||
dialog->updateContactStatusLight(groupId);
|
||||
if (dialog->isContactWidgetActive(groupId)) {
|
||||
if (dialog->isContactActive(groupId)) {
|
||||
dialog->updateTitleAndStatusIcon();
|
||||
}
|
||||
}
|
||||
|
||||
bool ContentDialogManager::isContactWidgetActive(const ContactId& contactId)
|
||||
bool ContentDialogManager::isContactActive(const ContactId& contactId)
|
||||
{
|
||||
const auto dialog = contactDialogs.value(contactId);
|
||||
if (dialog == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return dialog->isContactWidgetActive(contactId);
|
||||
return dialog->isContactActive(contactId);
|
||||
}
|
||||
|
||||
ContentDialog* ContentDialogManager::getFriendDialog(const ToxPk& friendPk) const
|
||||
|
@ -181,3 +181,13 @@ void ContentDialogManager::onDialogClose()
|
|||
|
||||
removeDialog(dialog, contactDialogs);
|
||||
}
|
||||
|
||||
IDialogs* ContentDialogManager::getFriendDialogs(const ToxPk& friendPk) const
|
||||
{
|
||||
return getFriendDialog(friendPk);
|
||||
}
|
||||
|
||||
IDialogs* ContentDialogManager::getGroupDialogs(const GroupId& groupId) const
|
||||
{
|
||||
return getGroupDialog(groupId);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright © 2018 by The qTox Project Contributors
|
||||
Copyright © 2018-2019 by The qTox Project Contributors
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
|||
#include "src/core/contactid.h"
|
||||
#include "src/core/toxpk.h"
|
||||
#include "src/core/groupid.h"
|
||||
#include "src/model/dialogs/idialogsmanager.h"
|
||||
#include "contentdialog.h"
|
||||
|
||||
#include <QObject>
|
||||
|
@ -30,7 +31,7 @@
|
|||
/**
|
||||
* @breaf Manage all content dialogs
|
||||
*/
|
||||
class ContentDialogManager : public QObject
|
||||
class ContentDialogManager : public QObject, public IDialogsManager
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -39,10 +40,13 @@ public:
|
|||
void focusContact(const ContactId& contactId);
|
||||
void updateFriendStatus(const ToxPk& friendPk);
|
||||
void updateGroupStatus(const GroupId& friendPk);
|
||||
bool isContactWidgetActive(const ContactId& contactId);
|
||||
bool isContactActive(const ContactId& contactId);
|
||||
ContentDialog* getFriendDialog(const ToxPk& friendPk) const;
|
||||
ContentDialog* getGroupDialog(const GroupId& friendPk) const;
|
||||
|
||||
IDialogs* getFriendDialogs(const ToxPk& friendPk) const;
|
||||
IDialogs* getGroupDialogs(const GroupId& groupId) const;
|
||||
|
||||
FriendWidget* addFriendToDialog(ContentDialog* dialog, std::shared_ptr<FriendChatroom> chatroom, GenericChatForm* form);
|
||||
GroupWidget* addGroupToDialog(ContentDialog* dialog, std::shared_ptr<GroupChatroom> chatroom, GenericChatForm* form);
|
||||
|
||||
|
|
|
@ -110,13 +110,13 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
|||
const auto contentDialog = ContentDialogManager::getInstance()->getFriendDialog(friendPk);
|
||||
|
||||
// TODO: move to model
|
||||
if (!contentDialog || contentDialog->chatroomWidgetCount() > 1) {
|
||||
if (!contentDialog || contentDialog->chatroomCount() > 1) {
|
||||
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->hasContactWidget(friendPk)) {
|
||||
if (contentDialog && contentDialog->hasContact(friendPk)) {
|
||||
const auto removeChatWindow = menu.addAction(tr("Remove chat from this window"));
|
||||
connect(removeChatWindow, &QAction::triggered, this, &FriendWidget::removeChatWindow);
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ void FriendWidget::onContextMenuCalled(QContextMenuEvent* event)
|
|||
menu.addSeparator();
|
||||
|
||||
// TODO: move to model
|
||||
if (!contentDialog || !contentDialog->hasContactWidget(friendPk)) {
|
||||
if (!contentDialog || !contentDialog->hasContact(friendPk)) {
|
||||
const auto removeAction =
|
||||
menu.addAction(tr("Remove friend", "Menu to remove the friend from our friendlist"));
|
||||
connect(removeAction, &QAction::triggered, this, [=]() { emit removeFriend(friendPk); },
|
||||
|
|
|
@ -90,13 +90,13 @@ void GroupWidget::contextMenuEvent(QContextMenuEvent* event)
|
|||
|
||||
// TODO: Move to model
|
||||
ContentDialog* contentDialog = ContentDialogManager::getInstance()->getGroupDialog(groupId);
|
||||
const bool notAlone = contentDialog != nullptr && contentDialog->chatroomWidgetCount() > 1;
|
||||
const bool notAlone = contentDialog != nullptr && contentDialog->chatroomCount() > 1;
|
||||
|
||||
if (contentDialog == nullptr || notAlone) {
|
||||
openChatWindow = menu.addAction(tr("Open chat in new window"));
|
||||
}
|
||||
|
||||
if (contentDialog && contentDialog->hasContactWidget(groupId)) {
|
||||
if (contentDialog && contentDialog->hasContact(groupId)) {
|
||||
removeChatWindow = menu.addAction(tr("Remove chat from this window"));
|
||||
}
|
||||
|
||||
|
|
|
@ -1353,7 +1353,7 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, b
|
|||
|
||||
if (contentDialog != nullptr) {
|
||||
currentWindow = contentDialog->window();
|
||||
hasActive = ContentDialogManager::getInstance()->isContactWidgetActive(friendId);
|
||||
hasActive = ContentDialogManager::getInstance()->isContactActive(friendId);
|
||||
} else {
|
||||
if (settings.getSeparateWindow() && settings.getShowWindow()) {
|
||||
if (settings.getDontGroupWindows()) {
|
||||
|
@ -1367,7 +1367,7 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, b
|
|||
|
||||
addFriendDialog(f, contentDialog);
|
||||
currentWindow = contentDialog->window();
|
||||
hasActive = ContentDialogManager::getInstance()->isContactWidgetActive(friendId);
|
||||
hasActive = ContentDialogManager::getInstance()->isContactActive(friendId);
|
||||
} else {
|
||||
currentWindow = window();
|
||||
FriendWidget* widget = friendWidgets[friendId];
|
||||
|
@ -1416,7 +1416,7 @@ bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk,
|
|||
|
||||
if (contentDialog != nullptr) {
|
||||
currentWindow = contentDialog->window();
|
||||
hasActive = ContentDialogManager::getInstance()->isContactWidgetActive(groupId);
|
||||
hasActive = ContentDialogManager::getInstance()->isContactActive(groupId);
|
||||
} else {
|
||||
currentWindow = window();
|
||||
hasActive = widget == activeChatroomWidget;
|
||||
|
|
Loading…
Reference in New Issue
Block a user