mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Move FriendList global state into class
This commit is contained in:
parent
4a74b51bbc
commit
71c3f997b4
|
@ -26,9 +26,6 @@
|
|||
#include <QHash>
|
||||
#include <QMenu>
|
||||
|
||||
QHash<ToxPk, Friend*> FriendList::friendList;
|
||||
QHash<uint32_t, ToxPk> FriendList::id2key;
|
||||
|
||||
Friend* FriendList::addFriend(uint32_t friendId, const ToxPk& friendPk, Settings& settings)
|
||||
{
|
||||
auto friendChecker = friendList.find(friendPk);
|
||||
|
|
|
@ -21,10 +21,10 @@
|
|||
|
||||
#include <cstdint>
|
||||
|
||||
#include <QHash>
|
||||
|
||||
template <class T>
|
||||
class QList;
|
||||
template <class A, class B>
|
||||
class QHash;
|
||||
class Friend;
|
||||
class QByteArray;
|
||||
class QString;
|
||||
|
@ -34,15 +34,15 @@ class Settings;
|
|||
class FriendList
|
||||
{
|
||||
public:
|
||||
static Friend* addFriend(uint32_t friendId, const ToxPk& friendPk, Settings& settings);
|
||||
static Friend* findFriend(const ToxPk& friendPk);
|
||||
static const ToxPk& id2Key(uint32_t friendId);
|
||||
static QList<Friend*> getAllFriends();
|
||||
static void removeFriend(const ToxPk& friendPk, Settings& settings, bool fake = false);
|
||||
static void clear();
|
||||
static QString decideNickname(const ToxPk& friendPk, const QString& origName);
|
||||
Friend* addFriend(uint32_t friendId, const ToxPk& friendPk, Settings& settings);
|
||||
Friend* findFriend(const ToxPk& friendPk);
|
||||
const ToxPk& id2Key(uint32_t friendId);
|
||||
QList<Friend*> getAllFriends();
|
||||
void removeFriend(const ToxPk& friendPk, Settings& settings, bool fake = false);
|
||||
void clear();
|
||||
QString decideNickname(const ToxPk& friendPk, const QString& origName);
|
||||
|
||||
private:
|
||||
static QHash<ToxPk, Friend*> friendList;
|
||||
static QHash<uint32_t, ToxPk> id2key;
|
||||
QHash<ToxPk, Friend*> friendList;
|
||||
QHash<uint32_t, ToxPk> id2key;
|
||||
};
|
||||
|
|
|
@ -26,14 +26,14 @@
|
|||
QHash<const GroupId, Group*> GroupList::groupList;
|
||||
QHash<uint32_t, GroupId> GroupList::id2key;
|
||||
Group* GroupList::addGroup(Core& core, int groupNum, const GroupId& groupId, const QString& name, bool isAvGroupchat,
|
||||
const QString& selfName)
|
||||
const QString& selfName, FriendList& friendList)
|
||||
{
|
||||
auto checker = groupList.find(groupId);
|
||||
if (checker != groupList.end()) {
|
||||
qWarning() << "addGroup: groupId already taken";
|
||||
}
|
||||
|
||||
Group* newGroup = new Group(groupNum, groupId, name, isAvGroupchat, selfName, core, core);
|
||||
Group* newGroup = new Group(groupNum, groupId, name, isAvGroupchat, selfName, core, core, friendList);
|
||||
groupList[groupId] = newGroup;
|
||||
id2key[groupNum] = groupId;
|
||||
return newGroup;
|
||||
|
|
|
@ -28,11 +28,13 @@ template <class T>
|
|||
class QList;
|
||||
class Group;
|
||||
class QString;
|
||||
class FriendList;
|
||||
|
||||
class GroupList
|
||||
{
|
||||
public:
|
||||
static Group* addGroup(Core& core, int groupNum, const GroupId& persistentGroupId, const QString& name, bool isAvGroupchat, const QString& selfName);
|
||||
static Group* addGroup(Core& core, int groupNum, const GroupId& persistentGroupId,
|
||||
const QString& name, bool isAvGroupchat, const QString& selfName, FriendList& friendList);
|
||||
static Group* findGroup(const GroupId& groupId);
|
||||
static const GroupId& id2Key(uint32_t groupNum);
|
||||
static void removeGroup(const GroupId& groupId, bool fake = false);
|
||||
|
|
|
@ -71,12 +71,13 @@ bool handleActionPrefix(QString& content)
|
|||
} // namespace
|
||||
|
||||
ChatHistory::ChatHistory(Friend& f_, History* history_, const ICoreIdHandler& coreIdHandler_,
|
||||
const Settings& settings_, IMessageDispatcher& messageDispatcher)
|
||||
const Settings& settings_, IMessageDispatcher& messageDispatcher,
|
||||
FriendList& friendList)
|
||||
: f(f_)
|
||||
, history(history_)
|
||||
, settings(settings_)
|
||||
, coreIdHandler(coreIdHandler_)
|
||||
, sessionChatLog(getInitialChatLogIdx(), coreIdHandler_)
|
||||
, sessionChatLog(getInitialChatLogIdx(), coreIdHandler_, friendList)
|
||||
{
|
||||
connect(&messageDispatcher, &IMessageDispatcher::messageComplete, this,
|
||||
&ChatHistory::onMessageComplete);
|
||||
|
|
|
@ -27,13 +27,15 @@
|
|||
#include <QSet>
|
||||
|
||||
class Settings;
|
||||
class FriendList;
|
||||
|
||||
class ChatHistory : public IChatLog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ChatHistory(Friend& f_, History* history_, const ICoreIdHandler& coreIdHandler_,
|
||||
const Settings& settings_, IMessageDispatcher& messageDispatcher);
|
||||
const Settings& settings_, IMessageDispatcher& messageDispatcher,
|
||||
FriendList& friendList);
|
||||
const ChatLogItem& at(ChatLogIdx idx) const override;
|
||||
SearchResult searchForward(SearchPos startIdx, const QString& phrase,
|
||||
const ParameterSearch& parameter) const override;
|
||||
|
|
|
@ -27,11 +27,14 @@
|
|||
#include "src/model/group.h"
|
||||
#include "src/model/status.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/friendlist.h"
|
||||
|
||||
GroupChatroom::GroupChatroom(Group* group_, IDialogsManager* dialogsManager_, Core& core_)
|
||||
GroupChatroom::GroupChatroom(Group* group_, IDialogsManager* dialogsManager_, Core& core_,
|
||||
FriendList& friendList_)
|
||||
: group{group_}
|
||||
, dialogsManager{dialogsManager_}
|
||||
, core{core_}
|
||||
, friendList{friendList_}
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -58,12 +61,12 @@ void GroupChatroom::resetEventFlags()
|
|||
|
||||
bool GroupChatroom::friendExists(const ToxPk& pk)
|
||||
{
|
||||
return FriendList::findFriend(pk) != nullptr;
|
||||
return friendList.findFriend(pk) != nullptr;
|
||||
}
|
||||
|
||||
void GroupChatroom::inviteFriend(const ToxPk& pk)
|
||||
{
|
||||
const Friend* frnd = FriendList::findFriend(pk);
|
||||
const Friend* frnd = friendList.findFriend(pk);
|
||||
const auto friendId = frnd->getId();
|
||||
const auto groupId = group->getId();
|
||||
const auto canInvite = Status::isOnline(frnd->getStatus());
|
||||
|
|
|
@ -27,12 +27,14 @@ class Core;
|
|||
class IDialogsManager;
|
||||
class Group;
|
||||
class ToxPk;
|
||||
class FriendList;
|
||||
|
||||
class GroupChatroom : public QObject, public Chatroom
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
GroupChatroom(Group* group_, IDialogsManager* dialogsManager_, Core& core_);
|
||||
GroupChatroom(Group* group_, IDialogsManager* dialogsManager_, Core& core_,
|
||||
FriendList& friendList);
|
||||
|
||||
Chat* getChat() override;
|
||||
|
||||
|
@ -52,4 +54,5 @@ private:
|
|||
Group* group{nullptr};
|
||||
IDialogsManager* dialogsManager{nullptr};
|
||||
Core& core;
|
||||
FriendList& friendList;
|
||||
};
|
||||
|
|
|
@ -33,7 +33,8 @@ const int MAX_GROUP_TITLE_LENGTH = 128;
|
|||
} // namespace
|
||||
|
||||
Group::Group(int groupId_, const GroupId persistentGroupId, const QString& name, bool isAvGroupchat,
|
||||
const QString& selfName_, ICoreGroupQuery& groupQuery_, ICoreIdHandler& idHandler_)
|
||||
const QString& selfName_, ICoreGroupQuery& groupQuery_, ICoreIdHandler& idHandler_,
|
||||
FriendList& friendList_)
|
||||
: groupQuery(groupQuery_)
|
||||
, idHandler(idHandler_)
|
||||
, selfName{selfName_}
|
||||
|
@ -41,6 +42,7 @@ Group::Group(int groupId_, const GroupId persistentGroupId, const QString& name,
|
|||
, toxGroupNum(groupId_)
|
||||
, groupId{persistentGroupId}
|
||||
, avGroupchat{isAvGroupchat}
|
||||
, friendList{friendList_}
|
||||
{
|
||||
// in groupchats, we only notify on messages containing your name <-- dumb
|
||||
// sound notifications should be on all messages, but system popup notification
|
||||
|
@ -99,7 +101,7 @@ void Group::regeneratePeerList()
|
|||
if (pk == idHandler.getSelfPublicKey()) {
|
||||
peerDisplayNames[pk] = idHandler.getUsername();
|
||||
} else {
|
||||
peerDisplayNames[pk] = FriendList::decideNickname(pk, peers[i]);
|
||||
peerDisplayNames[pk] = friendList.decideNickname(pk, peers[i]);
|
||||
}
|
||||
}
|
||||
for (const auto& pk : oldPeerNames.keys()) {
|
||||
|
@ -124,7 +126,7 @@ void Group::regeneratePeerList()
|
|||
|
||||
void Group::updateUsername(ToxPk pk, const QString newName)
|
||||
{
|
||||
const QString displayName = FriendList::decideNickname(pk, newName);
|
||||
const QString displayName = friendList.decideNickname(pk, newName);
|
||||
assert(peerDisplayNames.contains(pk));
|
||||
if (peerDisplayNames[pk] != displayName) {
|
||||
// there could be no actual change even if their username changed due to an alias being set
|
||||
|
|
|
@ -31,12 +31,15 @@
|
|||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
class FriendList;
|
||||
|
||||
class Group : public Chat
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Group(int groupId_, const GroupId persistentGroupId, const QString& name, bool isAvGroupchat,
|
||||
const QString& selfName_, ICoreGroupQuery& groupQuery_, ICoreIdHandler& idHandler_);
|
||||
const QString& selfName_, ICoreGroupQuery& groupQuery_, ICoreIdHandler& idHandler_,
|
||||
FriendList& friendList);
|
||||
bool isAvGroupchat() const;
|
||||
uint32_t getId() const override;
|
||||
const GroupId& getPersistentId() const override;
|
||||
|
@ -79,4 +82,5 @@ private:
|
|||
int toxGroupNum;
|
||||
const GroupId groupId;
|
||||
bool avGroupchat;
|
||||
FriendList& friendList;
|
||||
};
|
||||
|
|
|
@ -107,9 +107,9 @@ firstItemAfterDate(QDate date, const std::map<ChatLogIdx, ChatLogItem>& items)
|
|||
});
|
||||
}
|
||||
|
||||
QString resolveToxPk(const ToxPk& pk)
|
||||
QString resolveToxPk(FriendList& friendList, const ToxPk& pk)
|
||||
{
|
||||
Friend* f = FriendList::findFriend(pk);
|
||||
Friend* f = friendList.findFriend(pk);
|
||||
if (f) {
|
||||
return f->getDisplayedName();
|
||||
}
|
||||
|
@ -125,16 +125,19 @@ QString resolveToxPk(const ToxPk& pk)
|
|||
}
|
||||
} // namespace
|
||||
|
||||
SessionChatLog::SessionChatLog(const ICoreIdHandler& coreIdHandler_)
|
||||
SessionChatLog::SessionChatLog(const ICoreIdHandler& coreIdHandler_, FriendList& friendList_)
|
||||
: coreIdHandler(coreIdHandler_)
|
||||
, friendList{friendList_}
|
||||
{}
|
||||
|
||||
/**
|
||||
* @brief Alternate constructor that allows for an initial index to be set
|
||||
*/
|
||||
SessionChatLog::SessionChatLog(ChatLogIdx initialIdx, const ICoreIdHandler& coreIdHandler_)
|
||||
SessionChatLog::SessionChatLog(ChatLogIdx initialIdx, const ICoreIdHandler& coreIdHandler_,
|
||||
FriendList& friendList_)
|
||||
: coreIdHandler(coreIdHandler_)
|
||||
, nextIdx(initialIdx)
|
||||
, friendList{friendList_}
|
||||
{}
|
||||
|
||||
SessionChatLog::~SessionChatLog() = default;
|
||||
|
@ -144,7 +147,7 @@ QString SessionChatLog::resolveSenderNameFromSender(const ToxPk& sender)
|
|||
bool isSelf = sender == coreIdHandler.getSelfPublicKey();
|
||||
QString myNickName = coreIdHandler.getUsername().isEmpty() ? sender.toString() : coreIdHandler.getUsername();
|
||||
|
||||
return isSelf ? myNickName : resolveToxPk(sender);
|
||||
return isSelf ? myNickName : resolveToxPk(friendList, sender);
|
||||
}
|
||||
|
||||
const ChatLogItem& SessionChatLog::at(ChatLogIdx idx) const
|
||||
|
|
|
@ -26,14 +26,15 @@
|
|||
#include <QObject>
|
||||
|
||||
struct SessionChatLogMetadata;
|
||||
|
||||
class FriendList;
|
||||
|
||||
class SessionChatLog : public IChatLog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SessionChatLog(const ICoreIdHandler& coreIdHandler_);
|
||||
SessionChatLog(ChatLogIdx initialIdx, const ICoreIdHandler& coreIdHandler_);
|
||||
SessionChatLog(const ICoreIdHandler& coreIdHandler_, FriendList& friendList);
|
||||
SessionChatLog(ChatLogIdx initialIdx, const ICoreIdHandler& coreIdHandler_,
|
||||
FriendList& friendList);
|
||||
|
||||
~SessionChatLog();
|
||||
const ChatLogItem& at(ChatLogIdx idx) const override;
|
||||
|
@ -95,4 +96,5 @@ private:
|
|||
* is marked as completed
|
||||
*/
|
||||
QMap<DispatchedMessageId, ChatLogIdx> outgoingMessages;
|
||||
FriendList& friendList;
|
||||
};
|
||||
|
|
|
@ -41,13 +41,15 @@
|
|||
QHash<int, CircleWidget*> CircleWidget::circleList;
|
||||
|
||||
CircleWidget::CircleWidget(const Core &core_, FriendListWidget* parent, int id_,
|
||||
Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager_)
|
||||
Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager_,
|
||||
FriendList& friendList_)
|
||||
: CategoryWidget(isCompact(), settings_, style_, parent)
|
||||
, id(id_)
|
||||
, core{core_}
|
||||
, settings{settings_}
|
||||
, style{style_}
|
||||
, messageBoxManager{messageBoxManager_}
|
||||
, friendList{friendList_}
|
||||
{
|
||||
setName(settings.getCircleName(id), false);
|
||||
circleList[id] = this;
|
||||
|
@ -103,10 +105,10 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
|
|||
if (selectedItem == renameAction) {
|
||||
editName();
|
||||
} else if (selectedItem == removeAction) {
|
||||
FriendListWidget* friendList = static_cast<FriendListWidget*>(parentWidget());
|
||||
moveFriendWidgets(friendList);
|
||||
FriendListWidget* friendListWidget = static_cast<FriendListWidget*>(parentWidget());
|
||||
moveFriendWidgets(friendListWidget);
|
||||
|
||||
friendList->removeCircleWidget(this);
|
||||
friendListWidget->removeCircleWidget(this);
|
||||
|
||||
int replacedCircle = settings.removeCircle(id);
|
||||
|
||||
|
@ -118,7 +120,7 @@ void CircleWidget::contextMenuEvent(QContextMenuEvent* event)
|
|||
|
||||
circleList.remove(replacedCircle);
|
||||
} else if (selectedItem == openAction) {
|
||||
ContentDialog* dialog = new ContentDialog(core, settings, style, messageBoxManager);
|
||||
ContentDialog* dialog = new ContentDialog(core, settings, style, messageBoxManager, friendList);
|
||||
emit newContentDialog(*dialog);
|
||||
for (int i = 0; i < friendOnlineLayout()->count(); ++i) {
|
||||
QWidget* const widget = friendOnlineLayout()->itemAt(i)->widget();
|
||||
|
@ -151,7 +153,7 @@ void CircleWidget::dragEnterEvent(QDragEnterEvent* event)
|
|||
return;
|
||||
}
|
||||
ToxPk toxPk(event->mimeData()->data("toxPk"));
|
||||
Friend* f = FriendList::findFriend(toxPk);
|
||||
Friend* f = friendList.findFriend(toxPk);
|
||||
if (f != nullptr)
|
||||
event->acceptProposedAction();
|
||||
|
||||
|
@ -179,7 +181,7 @@ void CircleWidget::dropEvent(QDropEvent* event)
|
|||
}
|
||||
// Check, that the user has a friend with the same ToxId
|
||||
ToxPk toxPk{event->mimeData()->data("toxPk")};
|
||||
Friend* f = FriendList::findFriend(toxPk);
|
||||
Friend* f = friendList.findFriend(toxPk);
|
||||
if (!f)
|
||||
return;
|
||||
|
||||
|
|
|
@ -26,13 +26,14 @@ class Core;
|
|||
class Settings;
|
||||
class Style;
|
||||
class IMessageBoxManager;
|
||||
class FriendList;
|
||||
|
||||
class CircleWidget final : public CategoryWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CircleWidget(const Core& core_, FriendListWidget* parent, int id_, Settings& settings,
|
||||
Style& style, IMessageBoxManager& messageboxManager);
|
||||
Style& style, IMessageBoxManager& messageboxManager, FriendList& friendList);
|
||||
~CircleWidget();
|
||||
|
||||
void editName();
|
||||
|
@ -61,4 +62,5 @@ private:
|
|||
Settings& settings;
|
||||
Style& style;
|
||||
IMessageBoxManager& messageBoxManager;
|
||||
FriendList& friendList;
|
||||
};
|
||||
|
|
|
@ -54,7 +54,8 @@ const QSize defaultSize(720, 400);
|
|||
} // namespace
|
||||
|
||||
ContentDialog::ContentDialog(const Core &core, Settings& settings_,
|
||||
Style& style_, IMessageBoxManager& messageBoxManager_, QWidget* parent)
|
||||
Style& style_, IMessageBoxManager& messageBoxManager_, FriendList& friendList_,
|
||||
QWidget* parent)
|
||||
: ActivateDialog(style_, parent, Qt::Window)
|
||||
, splitter{new QSplitter(this)}
|
||||
, friendLayout{new FriendListLayout(this)}
|
||||
|
@ -64,6 +65,7 @@ ContentDialog::ContentDialog(const Core &core, Settings& settings_,
|
|||
, settings{settings_}
|
||||
, style{style_}
|
||||
, messageBoxManager{messageBoxManager_}
|
||||
, friendList{friendList_}
|
||||
{
|
||||
friendLayout->setMargin(0);
|
||||
friendLayout->setSpacing(0);
|
||||
|
@ -481,7 +483,7 @@ void ContentDialog::dragEnterEvent(QDragEnterEvent* event)
|
|||
if (frnd) {
|
||||
assert(event->mimeData()->hasFormat("toxPk"));
|
||||
ToxPk toxPk{event->mimeData()->data("toxPk")};
|
||||
Friend* contact = FriendList::findFriend(toxPk);
|
||||
Friend* contact = friendList.findFriend(toxPk);
|
||||
if (!contact) {
|
||||
return;
|
||||
}
|
||||
|
@ -514,7 +516,7 @@ void ContentDialog::dropEvent(QDropEvent* event)
|
|||
if (frnd) {
|
||||
assert(event->mimeData()->hasFormat("toxPk"));
|
||||
const ToxPk toxId(event->mimeData()->data("toxPk"));
|
||||
Friend* contact = FriendList::findFriend(toxId);
|
||||
Friend* contact = friendList.findFriend(toxId);
|
||||
if (!contact) {
|
||||
return;
|
||||
}
|
||||
|
@ -647,7 +649,7 @@ void ContentDialog::setStatusMessage(const ToxPk& friendPk, const QString& messa
|
|||
void ContentDialog::updateFriendWidget(const ToxPk& friendPk, QString alias)
|
||||
{
|
||||
std::ignore = alias;
|
||||
Friend* f = FriendList::findFriend(friendPk);
|
||||
Friend* f = friendList.findFriend(friendPk);
|
||||
FriendWidget* friendWidget = qobject_cast<FriendWidget*>(chatWidgets[friendPk]);
|
||||
|
||||
Status::Status status = f->getStatus();
|
||||
|
|
|
@ -48,13 +48,15 @@ class QScrollArea;
|
|||
class Settings;
|
||||
class Style;
|
||||
class IMessageBoxManager;
|
||||
class FriendList;
|
||||
|
||||
class ContentDialog : public ActivateDialog, public IDialogs
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ContentDialog(const Core& core, Settings& settings, Style& style,
|
||||
IMessageBoxManager& messageBoxManager, QWidget* parent = nullptr);
|
||||
IMessageBoxManager& messageBoxManager, FriendList& friendList,
|
||||
QWidget* parent = nullptr);
|
||||
~ContentDialog() override;
|
||||
|
||||
FriendWidget* addFriend(std::shared_ptr<FriendChatroom> chatroom, GenericChatForm* form);
|
||||
|
@ -142,4 +144,5 @@ private:
|
|||
Settings& settings;
|
||||
Style& style;
|
||||
IMessageBoxManager& messageBoxManager;
|
||||
FriendList& friendList;
|
||||
};
|
||||
|
|
|
@ -41,6 +41,11 @@ void removeDialog(ContentDialog* dialog, QHash<const ChatId&, ContentDialog*>& d
|
|||
}
|
||||
} // namespace
|
||||
|
||||
ContentDialogManager::ContentDialogManager(FriendList& friendList_)
|
||||
: friendList{friendList_}
|
||||
{
|
||||
}
|
||||
|
||||
ContentDialog* ContentDialogManager::current()
|
||||
{
|
||||
return currentDialog;
|
||||
|
@ -132,7 +137,7 @@ void ContentDialogManager::updateFriendStatus(const ToxPk& friendPk)
|
|||
dialog->updateTitleAndStatusIcon();
|
||||
}
|
||||
|
||||
Friend* f = FriendList::findFriend(friendPk);
|
||||
Friend* f = friendList.findFriend(friendPk);
|
||||
dialog->updateFriendStatus(friendPk, f->getStatus());
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ class ContentDialogManager : public QObject, public IDialogsManager
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ContentDialogManager(FriendList& friendList);
|
||||
ContentDialog* current();
|
||||
bool chatWidgetExists(const ChatId& chatId);
|
||||
void focusChat(const ChatId& chatId);
|
||||
|
@ -64,4 +65,5 @@ private:
|
|||
ContentDialog* currentDialog = nullptr;
|
||||
|
||||
QHash<const ChatId&, ContentDialog*> chatDialogs;
|
||||
FriendList& friendList;
|
||||
};
|
||||
|
|
|
@ -110,9 +110,9 @@ ChatForm::ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_,
|
|||
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache_,
|
||||
SmileyPack& smileyPack_, CameraSource& cameraSource_, Settings& settings_,
|
||||
Style& style_, IMessageBoxManager& messageBoxManager,
|
||||
ContentDialogManager& contentDialogManager_)
|
||||
ContentDialogManager& contentDialogManager_, FriendList& friendList_)
|
||||
: GenericChatForm(profile.getCore(), chatFriend, chatLog_, messageDispatcher_,
|
||||
documentCache_, smileyPack_, settings_, style_, messageBoxManager)
|
||||
documentCache_, smileyPack_, settings_, style_, messageBoxManager, friendList_)
|
||||
, core{profile.getCore()}
|
||||
, f(chatFriend)
|
||||
, isTyping{false}
|
||||
|
|
|
@ -48,6 +48,7 @@ class Settings;
|
|||
class Style;
|
||||
class IMessageBoxManager;
|
||||
class ContentDialogManager;
|
||||
class FriendList;
|
||||
|
||||
class ChatForm : public GenericChatForm
|
||||
{
|
||||
|
@ -56,7 +57,7 @@ public:
|
|||
ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache, SmileyPack& smileyPack,
|
||||
CameraSource& cameraSource, Settings& settings, Style& style, IMessageBoxManager& messageBoxManager,
|
||||
ContentDialogManager& contentDialogManager);
|
||||
ContentDialogManager& contentDialogManager, FriendList& friendList);
|
||||
~ChatForm() override;
|
||||
void setStatusMessage(const QString& newMessage);
|
||||
|
||||
|
|
|
@ -169,8 +169,9 @@ namespace FileTransferList
|
|||
return static_cast<EditorAction>(in);
|
||||
}
|
||||
|
||||
Model::Model(QObject* parent)
|
||||
Model::Model(FriendList& friendList_, QObject* parent)
|
||||
: QAbstractTableModel(parent)
|
||||
, friendList{friendList_}
|
||||
{}
|
||||
|
||||
QVariant Model::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
|
@ -271,7 +272,7 @@ namespace FileTransferList
|
|||
return files[row].fileName;
|
||||
case Column::contact:
|
||||
{
|
||||
auto f = FriendList::findFriend(FriendList::id2Key(files[row].friendId));
|
||||
auto f = friendList.findFriend(friendList.id2Key(files[row].friendId));
|
||||
if (f == nullptr) {
|
||||
qWarning("Invalid friend for file transfer");
|
||||
return "Unknown";
|
||||
|
@ -429,7 +430,8 @@ namespace FileTransferList
|
|||
|
||||
} // namespace FileTransferList
|
||||
|
||||
FilesForm::FilesForm(CoreFile& coreFile, Settings& settings, Style& style, IMessageBoxManager& messageBoxManager_)
|
||||
FilesForm::FilesForm(CoreFile& coreFile, Settings& settings, Style& style,
|
||||
IMessageBoxManager& messageBoxManager_, FriendList& friendList)
|
||||
: QObject()
|
||||
, messageBoxManager{messageBoxManager_}
|
||||
{
|
||||
|
@ -440,8 +442,8 @@ FilesForm::FilesForm(CoreFile& coreFile, Settings& settings, Style& style, IMess
|
|||
head->setLayout(&headLayout);
|
||||
headLayout.addWidget(&headLabel);
|
||||
|
||||
recvdModel = new FileTransferList::Model(this);
|
||||
sentModel = new FileTransferList::Model(this);
|
||||
recvdModel = new FileTransferList::Model(friendList, this);
|
||||
sentModel = new FileTransferList::Model(friendList, this);
|
||||
|
||||
auto pauseFile = [&coreFile] (ToxFile file) {
|
||||
coreFile.pauseResumeFile(file.friendId, file.fileNum);
|
||||
|
|
|
@ -38,6 +38,7 @@ class Settings;
|
|||
class Style;
|
||||
class QFileInfo;
|
||||
class IMessageBoxManager;
|
||||
class FriendList;
|
||||
|
||||
namespace FileTransferList
|
||||
{
|
||||
|
@ -69,7 +70,7 @@ namespace FileTransferList
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Model(QObject* parent = nullptr);
|
||||
Model(FriendList& friendList, QObject* parent = nullptr);
|
||||
~Model() = default;
|
||||
|
||||
void onFileUpdated(const ToxFile& file);
|
||||
|
@ -87,6 +88,7 @@ namespace FileTransferList
|
|||
private:
|
||||
QHash<QByteArray /*file id*/, int /*row index*/> idToRow;
|
||||
std::vector<ToxFile> files;
|
||||
FriendList& friendList;
|
||||
};
|
||||
|
||||
class Delegate : public QStyledItemDelegate
|
||||
|
@ -117,7 +119,7 @@ class FilesForm : public QObject
|
|||
|
||||
public:
|
||||
FilesForm(CoreFile& coreFile, Settings& settings, Style& style,
|
||||
IMessageBoxManager& messageBoxManager);
|
||||
IMessageBoxManager& messageBoxManager, FriendList& friendList);
|
||||
~FilesForm();
|
||||
|
||||
bool isShown() const;
|
||||
|
|
|
@ -96,7 +96,7 @@ QString fontToCss(const QFont& font, const QString& name)
|
|||
*/
|
||||
QString GenericChatForm::resolveToxPk(const ToxPk& pk)
|
||||
{
|
||||
Friend* f = FriendList::findFriend(pk);
|
||||
Friend* f = friendList.findFriend(pk);
|
||||
if (f) {
|
||||
return f->getDisplayedName();
|
||||
}
|
||||
|
@ -139,7 +139,8 @@ QPushButton* createButton(const QString& name, T* self, Fun onClickSlot,
|
|||
GenericChatForm::GenericChatForm(const Core& core_, const Chat* chat, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache,
|
||||
SmileyPack& smileyPack_, Settings& settings_, Style& style_,
|
||||
IMessageBoxManager& messageBoxManager, QWidget* parent_)
|
||||
IMessageBoxManager& messageBoxManager, FriendList& friendList_,
|
||||
QWidget* parent_)
|
||||
: QWidget(parent_, Qt::Window)
|
||||
, core{core_}
|
||||
, audioInputFlag(false)
|
||||
|
@ -149,6 +150,7 @@ GenericChatForm::GenericChatForm(const Core& core_, const Chat* chat, IChatLog&
|
|||
, smileyPack{smileyPack_}
|
||||
, settings{settings_}
|
||||
, style{style_}
|
||||
, friendList{friendList_}
|
||||
{
|
||||
curRow = 0;
|
||||
headWidget = new ChatFormHeader(settings, style);
|
||||
|
|
|
@ -58,6 +58,7 @@ class SmileyPack;
|
|||
class Settings;
|
||||
class Style;
|
||||
class IMessageBoxManager;
|
||||
class FriendList;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
@ -76,7 +77,8 @@ public:
|
|||
GenericChatForm(const Core& core_, const Chat* chat, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache,
|
||||
SmileyPack& smileyPack, Settings& settings, Style& style,
|
||||
IMessageBoxManager& messageBoxmanager, QWidget* parent_ = nullptr);
|
||||
IMessageBoxManager& messageBoxmanager, FriendList& friendList,
|
||||
QWidget* parent_ = nullptr);
|
||||
~GenericChatForm() override;
|
||||
|
||||
void setName(const QString& newName);
|
||||
|
@ -84,7 +86,7 @@ public:
|
|||
|
||||
void addSystemInfoMessage(const QDateTime& datetime, SystemMessageType messageType,
|
||||
SystemMessage::Args messageArgs);
|
||||
static QString resolveToxPk(const ToxPk& pk);
|
||||
QString resolveToxPk(const ToxPk& pk);
|
||||
QDateTime getLatestTime() const;
|
||||
|
||||
signals:
|
||||
|
@ -175,4 +177,5 @@ protected:
|
|||
SmileyPack& smileyPack;
|
||||
Settings& settings;
|
||||
Style& style;
|
||||
FriendList& friendList;
|
||||
};
|
||||
|
|
|
@ -85,14 +85,16 @@ QString editName(const QString& name)
|
|||
|
||||
GroupChatForm::GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, Settings& settings_, DocumentCache& documentCache_,
|
||||
SmileyPack& smileyPack_, Style& style_, IMessageBoxManager& messageBoxManager)
|
||||
SmileyPack& smileyPack_, Style& style_, IMessageBoxManager& messageBoxManager,
|
||||
FriendList& friendList_)
|
||||
: GenericChatForm(core_, chatGroup, chatLog_, messageDispatcher_,
|
||||
documentCache_, smileyPack_, settings_, style_, messageBoxManager)
|
||||
documentCache_, smileyPack_, settings_, style_, messageBoxManager, friendList_)
|
||||
, core{core_}
|
||||
, group(chatGroup)
|
||||
, inCall(false)
|
||||
, settings(settings_)
|
||||
, style{style_}
|
||||
, friendList{friendList_}
|
||||
{
|
||||
nusersLabel = new QLabel();
|
||||
|
||||
|
@ -298,7 +300,7 @@ void GroupChatForm::dragEnterEvent(QDragEnterEvent* ev)
|
|||
return;
|
||||
}
|
||||
ToxPk toxPk{ev->mimeData()->data("toxPk")};
|
||||
Friend* frnd = FriendList::findFriend(toxPk);
|
||||
Friend* frnd = friendList.findFriend(toxPk);
|
||||
if (frnd)
|
||||
ev->acceptProposedAction();
|
||||
}
|
||||
|
@ -309,7 +311,7 @@ void GroupChatForm::dropEvent(QDropEvent* ev)
|
|||
return;
|
||||
}
|
||||
ToxPk toxPk{ev->mimeData()->data("toxPk")};
|
||||
Friend* frnd = FriendList::findFriend(toxPk);
|
||||
Friend* frnd = friendList.findFriend(toxPk);
|
||||
if (!frnd)
|
||||
return;
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ class DocumentCache;
|
|||
class SmileyPack;
|
||||
class Style;
|
||||
class IMessageBoxManager;
|
||||
class FriendList;
|
||||
|
||||
class GroupChatForm : public GenericChatForm
|
||||
{
|
||||
|
@ -47,7 +48,7 @@ public:
|
|||
GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, Settings& settings_,
|
||||
DocumentCache& documentCache, SmileyPack& smileyPack, Style& style,
|
||||
IMessageBoxManager& messageBoxManager);
|
||||
IMessageBoxManager& messageBoxManager, FriendList& friendList);
|
||||
~GroupChatForm();
|
||||
|
||||
void peerAudioPlaying(ToxPk peerPk);
|
||||
|
@ -89,4 +90,5 @@ private:
|
|||
bool inCall;
|
||||
Settings& settings;
|
||||
Style& style;
|
||||
FriendList& friendList;
|
||||
};
|
||||
|
|
|
@ -101,12 +101,13 @@ qint64 timeUntilTomorrow()
|
|||
|
||||
FriendListWidget::FriendListWidget(const Core &core_, Widget* parent,
|
||||
Settings& settings_, Style& style_, IMessageBoxManager& messageBoxManager_,
|
||||
bool groupsOnTop)
|
||||
FriendList& friendList_, bool groupsOnTop)
|
||||
: QWidget(parent)
|
||||
, core{core_}
|
||||
, settings{settings_}
|
||||
, style{style_}
|
||||
, messageBoxManager{messageBoxManager_}
|
||||
, friendList{friendList_}
|
||||
{
|
||||
int countContacts = core.getFriendList().size();
|
||||
manager = new FriendListManager(countContacts, this);
|
||||
|
@ -525,7 +526,7 @@ void FriendListWidget::dragEnterEvent(QDragEnterEvent* event)
|
|||
return;
|
||||
}
|
||||
ToxPk toxPk(event->mimeData()->data("toxPk"));
|
||||
Friend* frnd = FriendList::findFriend(toxPk);
|
||||
Friend* frnd = friendList.findFriend(toxPk);
|
||||
if (frnd)
|
||||
event->acceptProposedAction();
|
||||
}
|
||||
|
@ -541,7 +542,7 @@ void FriendListWidget::dropEvent(QDropEvent* event)
|
|||
// Check, that the user has a friend with the same ToxPk
|
||||
assert(event->mimeData()->hasFormat("toxPk"));
|
||||
const ToxPk toxPk{event->mimeData()->data("toxPk")};
|
||||
Friend* f = FriendList::findFriend(toxPk);
|
||||
Friend* f = friendList.findFriend(toxPk);
|
||||
if (!f)
|
||||
return;
|
||||
|
||||
|
@ -619,7 +620,7 @@ CircleWidget* FriendListWidget::createCircleWidget(int id)
|
|||
}
|
||||
|
||||
CircleWidget* circleWidget = new CircleWidget(core, this, id, settings, style,
|
||||
messageBoxManager);
|
||||
messageBoxManager, friendList);
|
||||
emit connectCircleWidget(*circleWidget);
|
||||
connect(this, &FriendListWidget::onCompactChanged, circleWidget, &CircleWidget::onCompactChanged);
|
||||
connect(circleWidget, &CircleWidget::renameRequested, this, &FriendListWidget::renameCircleWidget);
|
||||
|
|
|
@ -41,6 +41,7 @@ class IFriendListItem;
|
|||
class Settings;
|
||||
class Style;
|
||||
class IMessageBoxManager;
|
||||
class FriendList;
|
||||
|
||||
class FriendListWidget : public QWidget
|
||||
{
|
||||
|
@ -48,7 +49,8 @@ class FriendListWidget : public QWidget
|
|||
public:
|
||||
using SortingMode = Settings::FriendListSortingMode;
|
||||
FriendListWidget(const Core& core, Widget* parent, Settings& settings, Style& style,
|
||||
IMessageBoxManager& messageBoxManager, bool groupsOnTop = true);
|
||||
IMessageBoxManager& messageBoxManager, FriendList& friendList,
|
||||
bool groupsOnTop = true);
|
||||
~FriendListWidget();
|
||||
void setMode(SortingMode mode);
|
||||
SortingMode getMode() const;
|
||||
|
@ -104,4 +106,5 @@ private:
|
|||
Settings& settings;
|
||||
Style& style;
|
||||
IMessageBoxManager& messageBoxManager;
|
||||
FriendList& friendList;
|
||||
};
|
||||
|
|
|
@ -160,7 +160,8 @@ Widget::Widget(Profile &profile_, IAudioControl& audio_, CameraSource& cameraSou
|
|||
, cameraSource{cameraSource_}
|
||||
, style{style_}
|
||||
, messageBoxManager(messageBoxManager_)
|
||||
, contentDialogManager(new ContentDialogManager())
|
||||
, friendList(new FriendList())
|
||||
, contentDialogManager(new ContentDialogManager(*friendList))
|
||||
{
|
||||
installEventFilter(this);
|
||||
QString locale = settings.getTranslation();
|
||||
|
@ -267,7 +268,7 @@ void Widget::init()
|
|||
sharedMessageProcessorParams.reset(new MessageProcessor::SharedParams(core->getMaxMessageSize(), coreExt->getMaxExtendedMessageSize()));
|
||||
|
||||
chatListWidget = new FriendListWidget(*core, this, settings, style,
|
||||
messageBoxManager, settings.getGroupchatPosition());
|
||||
messageBoxManager, *friendList, settings.getGroupchatPosition());
|
||||
connect(chatListWidget, &FriendListWidget::searchCircle, this, &Widget::searchCircle);
|
||||
connect(chatListWidget, &FriendListWidget::connectCircleWidget, this,
|
||||
&Widget::connectCircleWidget);
|
||||
|
@ -295,7 +296,7 @@ void Widget::init()
|
|||
style.setThemeColor(settings, settings.getThemeColor());
|
||||
|
||||
CoreFile* coreFile = core->getCoreFile();
|
||||
filesForm = new FilesForm(*coreFile, settings, style, messageBoxManager);
|
||||
filesForm = new FilesForm(*coreFile, settings, style, messageBoxManager, *friendList);
|
||||
addFriendForm = new AddFriendForm(core->getSelfId(), settings, style,
|
||||
messageBoxManager, *core);
|
||||
groupInviteForm = new GroupInviteForm(settings, *core);
|
||||
|
@ -623,7 +624,7 @@ Widget::~Widget()
|
|||
removeGroup(g, true);
|
||||
}
|
||||
|
||||
for (Friend* f : FriendList::getAllFriends()) {
|
||||
for (Friend* f : friendList->getAllFriends()) {
|
||||
removeFriend(f, true);
|
||||
}
|
||||
|
||||
|
@ -640,7 +641,7 @@ Widget::~Widget()
|
|||
delete contentLayout;
|
||||
delete settingsWidget;
|
||||
|
||||
FriendList::clear();
|
||||
friendList->clear();
|
||||
GroupList::clear();
|
||||
delete trayMenu;
|
||||
delete ui;
|
||||
|
@ -1060,7 +1061,7 @@ void Widget::cleanupNotificationSound()
|
|||
|
||||
void Widget::incomingNotification(uint32_t friendNum)
|
||||
{
|
||||
const auto& friendId = FriendList::id2Key(friendNum);
|
||||
const auto& friendId = friendList->id2Key(friendNum);
|
||||
newFriendMessageAlert(friendId, {}, false);
|
||||
|
||||
// loop until call answered or rejected
|
||||
|
@ -1091,8 +1092,8 @@ void Widget::onStopNotification()
|
|||
*/
|
||||
void Widget::dispatchFile(ToxFile file)
|
||||
{
|
||||
const auto& friendId = FriendList::id2Key(file.friendId);
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
const auto& friendId = friendList->id2Key(file.friendId);
|
||||
Friend* f = friendList->findFriend(friendId);
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
|
@ -1132,7 +1133,7 @@ void Widget::dispatchFileWithBool(ToxFile file, bool pausedOrBroken)
|
|||
|
||||
void Widget::dispatchFileSendFailed(uint32_t friendId, const QString& fileName)
|
||||
{
|
||||
const auto& friendPk = FriendList::id2Key(friendId);
|
||||
const auto& friendPk = friendList->id2Key(friendId);
|
||||
|
||||
auto chatForm = chatForms.find(friendPk);
|
||||
if (chatForm == chatForms.end()) {
|
||||
|
@ -1154,7 +1155,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
|
|||
assert(core != nullptr);
|
||||
settings.updateFriendAddress(friendPk.toString());
|
||||
|
||||
Friend* newfriend = FriendList::addFriend(friendId, friendPk, settings);
|
||||
Friend* newfriend = friendList->addFriend(friendId, friendPk, settings);
|
||||
auto rawChatroom = new FriendChatroom(newfriend, contentDialogManager.get(), *core, settings);
|
||||
std::shared_ptr<FriendChatroom> chatroom(rawChatroom);
|
||||
const auto compact = settings.getCompactLayout();
|
||||
|
@ -1170,10 +1171,10 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
|
|||
// ChatHistory hooks them up in a very specific order
|
||||
auto chatHistory =
|
||||
std::make_shared<ChatHistory>(*newfriend, history, *core, settings,
|
||||
*friendMessageDispatcher);
|
||||
*friendMessageDispatcher, *friendList);
|
||||
auto friendForm = new ChatForm(profile, newfriend, *chatHistory,
|
||||
*friendMessageDispatcher, *documentCache, *smileyPack, cameraSource,
|
||||
settings, style, messageBoxManager, *contentDialogManager);
|
||||
settings, style, messageBoxManager, *contentDialogManager, *friendList);
|
||||
connect(friendForm, &ChatForm::updateFriendActivity, this, &Widget::updateFriendActivity);
|
||||
|
||||
friendMessageDispatchers[friendPk] = friendMessageDispatcher;
|
||||
|
@ -1243,8 +1244,8 @@ void Widget::addFriendFailed(const ToxPk& userId, const QString& errorInfo)
|
|||
|
||||
void Widget::onCoreFriendStatusChanged(int friendId, Status::Status status)
|
||||
{
|
||||
const auto& friendPk = FriendList::id2Key(friendId);
|
||||
Friend* f = FriendList::findFriend(friendPk);
|
||||
const auto& friendPk = friendList->id2Key(friendId);
|
||||
Friend* f = friendList->findFriend(friendPk);
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
|
@ -1288,8 +1289,8 @@ void Widget::onFriendStatusChanged(const ToxPk& friendPk, Status::Status status)
|
|||
|
||||
void Widget::onFriendStatusMessageChanged(int friendId, const QString& message)
|
||||
{
|
||||
const auto& friendPk = FriendList::id2Key(friendId);
|
||||
Friend* f = FriendList::findFriend(friendPk);
|
||||
const auto& friendPk = friendList->id2Key(friendId);
|
||||
Friend* f = friendList->findFriend(friendPk);
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
|
@ -1322,8 +1323,8 @@ void Widget::onFriendDisplayedNameChanged(const QString& displayed)
|
|||
|
||||
void Widget::onFriendUsernameChanged(int friendId, const QString& username)
|
||||
{
|
||||
const auto& friendPk = FriendList::id2Key(friendId);
|
||||
Friend* f = FriendList::findFriend(friendPk);
|
||||
const auto& friendPk = friendList->id2Key(friendId);
|
||||
Friend* f = friendList->findFriend(friendPk);
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
|
@ -1408,8 +1409,8 @@ void Widget::openDialog(GenericChatroomWidget* widget, bool newWindow)
|
|||
|
||||
void Widget::onFriendMessageReceived(uint32_t friendnumber, const QString& message, bool isAction)
|
||||
{
|
||||
const auto& friendId = FriendList::id2Key(friendnumber);
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
const auto& friendId = friendList->id2Key(friendnumber);
|
||||
Friend* f = friendList->findFriend(friendId);
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
|
@ -1419,8 +1420,8 @@ void Widget::onFriendMessageReceived(uint32_t friendnumber, const QString& messa
|
|||
|
||||
void Widget::onReceiptReceived(int friendId, ReceiptNum receipt)
|
||||
{
|
||||
const auto& friendKey = FriendList::id2Key(friendId);
|
||||
Friend* f = FriendList::findFriend(friendKey);
|
||||
const auto& friendKey = friendList->id2Key(friendId);
|
||||
Friend* f = friendList->findFriend(friendKey);
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
|
@ -1430,8 +1431,8 @@ void Widget::onReceiptReceived(int friendId, ReceiptNum receipt)
|
|||
|
||||
void Widget::onExtendedMessageSupport(uint32_t friendNumber, bool supported)
|
||||
{
|
||||
const auto& friendKey = FriendList::id2Key(friendNumber);
|
||||
Friend* f = FriendList::findFriend(friendKey);
|
||||
const auto& friendKey = friendList->id2Key(friendNumber);
|
||||
Friend* f = friendList->findFriend(friendKey);
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
|
@ -1441,13 +1442,13 @@ void Widget::onExtendedMessageSupport(uint32_t friendNumber, bool supported)
|
|||
|
||||
void Widget::onFriendExtMessageReceived(uint32_t friendNumber, const QString& message)
|
||||
{
|
||||
const auto& friendKey = FriendList::id2Key(friendNumber);
|
||||
const auto& friendKey = friendList->id2Key(friendNumber);
|
||||
friendMessageDispatchers[friendKey]->onExtMessageReceived(message);
|
||||
}
|
||||
|
||||
void Widget::onExtReceiptReceived(uint32_t friendNumber, uint64_t receiptId)
|
||||
{
|
||||
const auto& friendKey = FriendList::id2Key(friendNumber);
|
||||
const auto& friendKey = friendList->id2Key(friendNumber);
|
||||
friendMessageDispatchers[friendKey]->onExtReceiptReceived(receiptId);
|
||||
}
|
||||
|
||||
|
@ -1557,7 +1558,7 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, b
|
|||
bool hasActive;
|
||||
QWidget* currentWindow;
|
||||
ContentDialog* contentDialog = contentDialogManager->getFriendDialog(friendId);
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
Friend* f = friendList->findFriend(friendId);
|
||||
|
||||
if (contentDialog != nullptr) {
|
||||
currentWindow = contentDialog->window();
|
||||
|
@ -1724,7 +1725,7 @@ void Widget::onFriendRequestReceived(const ToxPk& friendPk, const QString& messa
|
|||
|
||||
void Widget::onFileReceiveRequested(const ToxFile& file)
|
||||
{
|
||||
const ToxPk& friendPk = FriendList::id2Key(file.friendId);
|
||||
const ToxPk& friendPk = friendList->id2Key(file.friendId);
|
||||
newFriendMessageAlert(friendPk, {}, true, file.fileName, file.progress.getFileSize());
|
||||
}
|
||||
|
||||
|
@ -1771,7 +1772,7 @@ void Widget::removeFriend(Friend* f, bool fake)
|
|||
lastDialog->removeFriend(friendPk);
|
||||
}
|
||||
|
||||
FriendList::removeFriend(friendPk, settings, fake);
|
||||
friendList->removeFriend(friendPk, settings, fake);
|
||||
if (!fake) {
|
||||
core->removeFriend(f->getId());
|
||||
// aliases aren't supported for non-friend peers in groups, revert to basic username
|
||||
|
@ -1796,7 +1797,7 @@ void Widget::removeFriend(Friend* f, bool fake)
|
|||
|
||||
void Widget::removeFriend(const ToxPk& friendId)
|
||||
{
|
||||
removeFriend(FriendList::findFriend(friendId), false);
|
||||
removeFriend(friendList->findFriend(friendId), false);
|
||||
}
|
||||
|
||||
void Widget::onDialogShown(GenericChatroomWidget* widget)
|
||||
|
@ -1837,7 +1838,8 @@ void Widget::onUpdateAvailable()
|
|||
|
||||
ContentDialog* Widget::createContentDialog() const
|
||||
{
|
||||
ContentDialog* contentDialog = new ContentDialog(*core, settings, style, messageBoxManager);
|
||||
ContentDialog* contentDialog = new ContentDialog(*core, settings, style,
|
||||
messageBoxManager, *friendList);
|
||||
|
||||
registerContentDialog(*contentDialog);
|
||||
return contentDialog;
|
||||
|
@ -1948,7 +1950,7 @@ ContentLayout* Widget::createContentDialog(DialogType type) const
|
|||
|
||||
void Widget::copyFriendIdToClipboard(const ToxPk& friendId)
|
||||
{
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
Friend* f = friendList->findFriend(friendId);
|
||||
if (f != nullptr) {
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
clipboard->setText(friendId.toString(), QClipboard::Clipboard);
|
||||
|
@ -1958,8 +1960,8 @@ void Widget::copyFriendIdToClipboard(const ToxPk& friendId)
|
|||
void Widget::onGroupInviteReceived(const GroupInvite& inviteInfo)
|
||||
{
|
||||
const uint32_t friendId = inviteInfo.getFriendId();
|
||||
const ToxPk& friendPk = FriendList::id2Key(friendId);
|
||||
const Friend* f = FriendList::findFriend(friendPk);
|
||||
const ToxPk& friendPk = friendList->id2Key(friendId);
|
||||
const Friend* f = friendList->findFriend(friendPk);
|
||||
updateFriendActivity(*f);
|
||||
|
||||
const uint8_t confType = inviteInfo.getType();
|
||||
|
@ -2019,7 +2021,7 @@ void Widget::onGroupPeerNameChanged(uint32_t groupnumber, const ToxPk& peerPk, c
|
|||
Group* g = GroupList::findGroup(groupId);
|
||||
assert(g);
|
||||
|
||||
const QString setName = FriendList::decideNickname(peerPk, newName);
|
||||
const QString setName = friendList->decideNickname(peerPk, newName);
|
||||
g->updateUsername(peerPk, newName);
|
||||
}
|
||||
|
||||
|
@ -2115,7 +2117,8 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
|
|||
const auto groupName = tr("Groupchat #%1").arg(groupnumber);
|
||||
const bool enabled = core->getGroupAvEnabled(groupnumber);
|
||||
Group* newgroup =
|
||||
GroupList::addGroup(*core, groupnumber, groupId, groupName, enabled, core->getUsername());
|
||||
GroupList::addGroup(*core, groupnumber, groupId, groupName, enabled, core->getUsername(),
|
||||
*friendList);
|
||||
assert(newgroup);
|
||||
|
||||
if (enabled) {
|
||||
|
@ -2125,7 +2128,8 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
|
|||
av->invalidateGroupCallPeerSource(*newgroup, user);
|
||||
});
|
||||
}
|
||||
auto rawChatroom = new GroupChatroom(newgroup, contentDialogManager.get(), *core);
|
||||
auto rawChatroom = new GroupChatroom(newgroup, contentDialogManager.get(), *core,
|
||||
*friendList);
|
||||
std::shared_ptr<GroupChatroom> chatroom(rawChatroom);
|
||||
|
||||
const auto compact = settings.getCompactLayout();
|
||||
|
@ -2134,7 +2138,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
|
|||
auto messageDispatcher =
|
||||
std::make_shared<GroupMessageDispatcher>(*newgroup, std::move(messageProcessor), *core,
|
||||
*core, settings);
|
||||
auto groupChatLog = std::make_shared<SessionChatLog>(*core);
|
||||
auto groupChatLog = std::make_shared<SessionChatLog>(*core, *friendList);
|
||||
|
||||
connect(messageDispatcher.get(), &IMessageDispatcher::messageReceived, groupChatLog.get(),
|
||||
&SessionChatLog::onMessageReceived);
|
||||
|
@ -2159,7 +2163,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
|
|||
groupAlertConnections.insert(groupId, notifyReceivedConnection);
|
||||
|
||||
auto form = new GroupChatForm(*core, newgroup, *groupChatLog, *messageDispatcher,
|
||||
settings, *documentCache, *smileyPack, style, messageBoxManager);
|
||||
settings, *documentCache, *smileyPack, style, messageBoxManager, *friendList);
|
||||
connect(&settings, &Settings::nameColorsChanged, form, &GenericChatForm::setColorizedNames);
|
||||
form->setColorizedNames(settings.getEnableGroupChatsColor());
|
||||
groupMessageDispatchers[groupId] = messageDispatcher;
|
||||
|
@ -2367,8 +2371,8 @@ void Widget::onGroupSendFailed(uint32_t groupnumber)
|
|||
|
||||
void Widget::onFriendTypingChanged(uint32_t friendnumber, bool isTyping)
|
||||
{
|
||||
const auto& friendId = FriendList::id2Key(friendnumber);
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
const auto& friendId = friendList->id2Key(friendnumber);
|
||||
Friend* f = friendList->findFriend(friendId);
|
||||
if (!f) {
|
||||
return;
|
||||
}
|
||||
|
@ -2443,7 +2447,7 @@ bool Widget::filterOnline(FilterCriteria index)
|
|||
|
||||
void Widget::clearAllReceipts()
|
||||
{
|
||||
QList<Friend*> frnds = FriendList::getAllFriends();
|
||||
QList<Friend*> frnds = friendList->getAllFriends();
|
||||
for (Friend* f : frnds) {
|
||||
friendMessageDispatchers[f->getPublicKey()]->clearOutgoingMessages();
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "src/core/toxpk.h"
|
||||
#include "src/model/friendmessagedispatcher.h"
|
||||
#include "src/model/groupmessagedispatcher.h"
|
||||
#include "src/friendlist.h"
|
||||
#if DESKTOP_NOTIFICATIONS
|
||||
#include "src/model/notificationgenerator.h"
|
||||
#include "src/platform/desktop_notifications/desktopnotify.h"
|
||||
|
@ -392,6 +393,7 @@ private:
|
|||
CameraSource& cameraSource;
|
||||
Style& style;
|
||||
IMessageBoxManager& messageBoxManager;
|
||||
std::unique_ptr<FriendList> friendList;
|
||||
std::unique_ptr<ContentDialogManager> contentDialogManager;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "src/model/message.h"
|
||||
#include "src/persistence/settings.h"
|
||||
#include "src/persistence/igroupsettings.h"
|
||||
#include "src/friendlist.h"
|
||||
#include "util/interface.h"
|
||||
|
||||
#include "mock/mockcoreidhandler.h"
|
||||
|
@ -136,6 +137,7 @@ private:
|
|||
std::set<DispatchedMessageId> outgoingMessages;
|
||||
std::deque<Message> sentMessages;
|
||||
std::deque<Message> receivedMessages;
|
||||
std::unique_ptr<FriendList> friendList;
|
||||
};
|
||||
|
||||
TestGroupMessageDispatcher::TestGroupMessageDispatcher() {}
|
||||
|
@ -145,11 +147,13 @@ TestGroupMessageDispatcher::TestGroupMessageDispatcher() {}
|
|||
*/
|
||||
void TestGroupMessageDispatcher::init()
|
||||
{
|
||||
friendList = std::unique_ptr<FriendList>(new FriendList());
|
||||
groupSettings = std::unique_ptr<MockGroupSettings>(new MockGroupSettings());
|
||||
groupQuery = std::unique_ptr<MockGroupQuery>(new MockGroupQuery());
|
||||
coreIdHandler = std::unique_ptr<MockCoreIdHandler>(new MockCoreIdHandler());
|
||||
g = std::unique_ptr<Group>(
|
||||
new Group(0, GroupId(), "TestGroup", false, "me", *groupQuery, *coreIdHandler));
|
||||
new Group(0, GroupId(), "TestGroup", false, "me", *groupQuery, *coreIdHandler,
|
||||
*friendList));
|
||||
messageSender = std::unique_ptr<MockGroupMessageSender>(new MockGroupMessageSender());
|
||||
sharedProcessorParams =
|
||||
std::unique_ptr<MessageProcessor::SharedParams>(new MessageProcessor::SharedParams(tox_max_message_length(), 10 * 1024 * 1024));
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
*/
|
||||
|
||||
#include "src/model/notificationgenerator.h"
|
||||
#include "src/friendlist.h"
|
||||
|
||||
#include "mock/mockcoreidhandler.h"
|
||||
#include "mock/mockgroupquery.h"
|
||||
|
@ -89,10 +90,12 @@ private:
|
|||
std::unique_ptr<NotificationGenerator> notificationGenerator;
|
||||
std::unique_ptr<MockGroupQuery> groupQuery;
|
||||
std::unique_ptr<MockCoreIdHandler> coreIdHandler;
|
||||
std::unique_ptr<FriendList> friendList;
|
||||
};
|
||||
|
||||
void TestNotificationGenerator::init()
|
||||
{
|
||||
friendList.reset(new FriendList());
|
||||
notificationSettings.reset(new MockNotificationSettings());
|
||||
notificationGenerator.reset(new NotificationGenerator(*notificationSettings, nullptr));
|
||||
groupQuery.reset(new MockGroupQuery());
|
||||
|
@ -139,7 +142,7 @@ void TestNotificationGenerator::testNotificationClear()
|
|||
|
||||
void TestNotificationGenerator::testGroupMessage()
|
||||
{
|
||||
Group g(0, GroupId(0), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
||||
Group g(0, GroupId(0), "groupName", false, "selfName", *groupQuery, *coreIdHandler, *friendList);
|
||||
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
||||
g.updateUsername(sender, "sender1");
|
||||
|
||||
|
@ -150,7 +153,7 @@ void TestNotificationGenerator::testGroupMessage()
|
|||
|
||||
void TestNotificationGenerator::testMultipleGroupMessages()
|
||||
{
|
||||
Group g(0, GroupId(0), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
||||
Group g(0, GroupId(0), "groupName", false, "selfName", *groupQuery, *coreIdHandler, *friendList);
|
||||
|
||||
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
||||
g.updateUsername(sender, "sender1");
|
||||
|
@ -182,8 +185,8 @@ void TestNotificationGenerator::testMultipleFriendSourceMessages()
|
|||
|
||||
void TestNotificationGenerator::testMultipleGroupSourceMessages()
|
||||
{
|
||||
Group g(0, GroupId(QByteArray(32, 0)), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
||||
Group g2(1, GroupId(QByteArray(32, 1)), "groupName2", false, "selfName", *groupQuery, *coreIdHandler);
|
||||
Group g(0, GroupId(QByteArray(32, 0)), "groupName", false, "selfName", *groupQuery, *coreIdHandler, *friendList);
|
||||
Group g2(1, GroupId(QByteArray(32, 1)), "groupName2", false, "selfName", *groupQuery, *coreIdHandler, *friendList);
|
||||
|
||||
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
||||
g.updateUsername(sender, "sender1");
|
||||
|
@ -200,7 +203,7 @@ void TestNotificationGenerator::testMixedSourceMessages()
|
|||
Friend f(0, ToxPk());
|
||||
f.setName("friend");
|
||||
|
||||
Group g(0, GroupId(QByteArray(32, 0)), "group", false, "selfName", *groupQuery, *coreIdHandler);
|
||||
Group g(0, GroupId(QByteArray(32, 0)), "group", false, "selfName", *groupQuery, *coreIdHandler, *friendList);
|
||||
|
||||
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
||||
g.updateUsername(sender, "sender1");
|
||||
|
@ -315,7 +318,7 @@ void TestNotificationGenerator::testSimpleFileTransfer()
|
|||
|
||||
void TestNotificationGenerator::testSimpleGroupMessage()
|
||||
{
|
||||
Group g(0, GroupId(0), "groupName", false, "selfName", *groupQuery, *coreIdHandler);
|
||||
Group g(0, GroupId(0), "groupName", false, "selfName", *groupQuery, *coreIdHandler, *friendList);
|
||||
auto sender = groupQuery->getGroupPeerPk(0, 0);
|
||||
g.updateUsername(sender, "sender1");
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@ private slots:
|
|||
private:
|
||||
MockCoreIdHandler idHandler;
|
||||
std::unique_ptr<SessionChatLog> chatLog;
|
||||
std::unique_ptr<FriendList> friendList;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -79,7 +80,8 @@ private:
|
|||
*/
|
||||
void TestSessionChatLog::init()
|
||||
{
|
||||
chatLog = std::unique_ptr<SessionChatLog>(new SessionChatLog(idHandler));
|
||||
friendList = std::unique_ptr<FriendList>(new FriendList());
|
||||
chatLog = std::unique_ptr<SessionChatLog>(new SessionChatLog(idHandler, *friendList));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -28,7 +28,7 @@ class TestFileTransferList : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
|
||||
void init();
|
||||
void testFileTransferListConversion();
|
||||
void testEditorActionConversion();
|
||||
|
||||
|
@ -44,14 +44,22 @@ private slots:
|
|||
void testAvatarIgnored();
|
||||
void testMultipleFiles();
|
||||
void testFileRemoval();
|
||||
private:
|
||||
std::unique_ptr<FileTransferList::Model> model;
|
||||
std::unique_ptr<FriendList> friendList;
|
||||
};
|
||||
|
||||
using namespace FileTransferList;
|
||||
|
||||
void TestFileTransferList::init()
|
||||
{
|
||||
friendList = std::unique_ptr<FriendList>(new FriendList());
|
||||
model = std::unique_ptr<Model>(new Model(*friendList));
|
||||
}
|
||||
|
||||
void TestFileTransferList::testFileTransferListConversion()
|
||||
{
|
||||
Model model;
|
||||
for (int i = 0; i < model.columnCount(); ++i) {
|
||||
for (int i = 0; i < model->columnCount(); ++i) {
|
||||
QVERIFY(toFileTransferListColumn(i) != Column::invalid);
|
||||
}
|
||||
QCOMPARE(toFileTransferListColumn(100), Column::invalid);
|
||||
|
@ -66,14 +74,12 @@ void TestFileTransferList::testEditorActionConversion()
|
|||
|
||||
void TestFileTransferList::testFileName()
|
||||
{
|
||||
Model model;
|
||||
|
||||
ToxFile file;
|
||||
file.fileKind = TOX_FILE_KIND_DATA;
|
||||
file.fileName = "Test";
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
|
||||
const auto idx = model.index(0, static_cast<int>(Column::fileName));
|
||||
const auto idx = model->index(0, static_cast<int>(Column::fileName));
|
||||
const auto fileName = idx.data();
|
||||
|
||||
QCOMPARE(fileName.toString(), QString("Test"));
|
||||
|
@ -81,13 +87,11 @@ void TestFileTransferList::testFileName()
|
|||
|
||||
void TestFileTransferList::testProgress()
|
||||
{
|
||||
Model model;
|
||||
|
||||
ToxFile file(0, 0, "", "", 1000, ToxFile::FileDirection::SENDING);
|
||||
file.progress.addSample(100, QTime(1, 0, 0));
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
|
||||
const auto idx = model.index(0, static_cast<int>(Column::progress));
|
||||
const auto idx = model->index(0, static_cast<int>(Column::progress));
|
||||
const auto progress = idx.data();
|
||||
|
||||
// Progress should be in percent units, 100/1000 == 10
|
||||
|
@ -96,12 +100,10 @@ void TestFileTransferList::testProgress()
|
|||
|
||||
void TestFileTransferList::testSize()
|
||||
{
|
||||
Model model;
|
||||
|
||||
ToxFile file(0, 0, "", "", 1000, ToxFile::FileDirection::SENDING);
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
|
||||
const auto idx = model.index(0, static_cast<int>(Column::size));
|
||||
const auto idx = model->index(0, static_cast<int>(Column::size));
|
||||
auto size = idx.data();
|
||||
|
||||
// Size should be a human readable string
|
||||
|
@ -109,21 +111,19 @@ void TestFileTransferList::testSize()
|
|||
|
||||
// 1GB + a little to avoid floating point inaccuracy
|
||||
file = ToxFile(0, 0, "", "", 1024 * 1024 * 1024 + 2, ToxFile::FileDirection::SENDING);
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
size = idx.data();
|
||||
QCOMPARE(size.toString(), QString("1.00GiB"));
|
||||
}
|
||||
|
||||
void TestFileTransferList::testSpeed()
|
||||
{
|
||||
Model model;
|
||||
|
||||
ToxFile file(0, 0, "", "", 1024 * 1024, ToxFile::FileDirection::SENDING);
|
||||
file.progress.addSample(100 * 1024, QTime(1, 0, 0));
|
||||
file.progress.addSample(200 * 1024, QTime(1, 0, 1));
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
|
||||
const auto idx = model.index(0, static_cast<int>(Column::speed));
|
||||
const auto idx = model->index(0, static_cast<int>(Column::speed));
|
||||
const auto speed = idx.data();
|
||||
|
||||
// Speed should be a human readable string
|
||||
|
@ -132,20 +132,18 @@ void TestFileTransferList::testSpeed()
|
|||
|
||||
void TestFileTransferList::testStatus()
|
||||
{
|
||||
Model model;
|
||||
|
||||
ToxFile file(0, 0, "", "", 1024 * 1024, ToxFile::FileDirection::SENDING);
|
||||
file.status = ToxFile::TRANSMITTING;
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
|
||||
const auto idx = model.index(0, static_cast<int>(Column::status));
|
||||
const auto idx = model->index(0, static_cast<int>(Column::status));
|
||||
auto status = idx.data();
|
||||
|
||||
QCOMPARE(status.toString(), QString("Transmitting"));
|
||||
|
||||
file.status = ToxFile::PAUSED;
|
||||
file.pauseStatus.remotePause();
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
status = idx.data();
|
||||
|
||||
QCOMPARE(status.toString(), QString("Remote paused"));
|
||||
|
@ -153,7 +151,7 @@ void TestFileTransferList::testStatus()
|
|||
file.status = ToxFile::PAUSED;
|
||||
file.pauseStatus.localPause();
|
||||
file.pauseStatus.remoteResume();
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
status = idx.data();
|
||||
|
||||
QCOMPARE(status.toString(), QString("Paused"));
|
||||
|
@ -161,87 +159,82 @@ void TestFileTransferList::testStatus()
|
|||
|
||||
void TestFileTransferList::testControl()
|
||||
{
|
||||
Model model;
|
||||
bool cancelCalled = false;
|
||||
bool pauseCalled = false;
|
||||
|
||||
QObject::connect(&model, &Model::cancel, [&] (ToxFile file) {
|
||||
QObject::connect(model.get(), &Model::cancel, [&] (ToxFile file) {
|
||||
std::ignore = file;
|
||||
cancelCalled = true;
|
||||
});
|
||||
|
||||
QObject::connect(&model, &Model::togglePause, [&] (ToxFile file) {
|
||||
QObject::connect(model.get(), &Model::togglePause, [&] (ToxFile file) {
|
||||
std::ignore = file;
|
||||
pauseCalled = true;
|
||||
});
|
||||
|
||||
ToxFile file(0, 0, "", "", 1024 * 1024, ToxFile::FileDirection::SENDING);
|
||||
file.status = ToxFile::TRANSMITTING;
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
|
||||
const auto idx = model.index(0, static_cast<int>(Column::control));
|
||||
model.setData(idx, static_cast<int>(EditorAction::pause));
|
||||
const auto idx = model->index(0, static_cast<int>(Column::control));
|
||||
model->setData(idx, static_cast<int>(EditorAction::pause));
|
||||
|
||||
QVERIFY(pauseCalled);
|
||||
QVERIFY(!cancelCalled);
|
||||
|
||||
pauseCalled = false;
|
||||
model.setData(idx, static_cast<int>(EditorAction::cancel));
|
||||
model->setData(idx, static_cast<int>(EditorAction::cancel));
|
||||
QVERIFY(!pauseCalled);
|
||||
QVERIFY(cancelCalled);
|
||||
|
||||
file.status = ToxFile::TRANSMITTING;
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
// True if paused
|
||||
QCOMPARE(idx.data().toBool(), false);
|
||||
|
||||
file.status = ToxFile::PAUSED;
|
||||
file.pauseStatus.localPause();
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
// True if _local_ paused
|
||||
QCOMPARE(idx.data().toBool(), true);
|
||||
}
|
||||
|
||||
void TestFileTransferList::testAvatarIgnored()
|
||||
{
|
||||
Model model;
|
||||
|
||||
ToxFile file;
|
||||
file.fileKind = TOX_FILE_KIND_AVATAR;
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
|
||||
QCOMPARE(model.rowCount(), 0);
|
||||
QCOMPARE(model->rowCount(), 0);
|
||||
}
|
||||
|
||||
void TestFileTransferList::testMultipleFiles()
|
||||
{
|
||||
Model model;
|
||||
|
||||
ToxFile file;
|
||||
file.resumeFileId = QByteArray();
|
||||
file.fileKind = TOX_FILE_KIND_DATA;
|
||||
file.status = ToxFile::TRANSMITTING;
|
||||
file.fileName = "a";
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
|
||||
// File map keys off resume file ID
|
||||
file.resumeFileId = QByteArray("asdfasdf");
|
||||
file.fileName = "b";
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
|
||||
QCOMPARE(model.rowCount(), 2);
|
||||
QCOMPARE(model->rowCount(), 2);
|
||||
|
||||
auto idx = model.index(0, static_cast<int>(Column::fileName));
|
||||
auto idx = model->index(0, static_cast<int>(Column::fileName));
|
||||
QCOMPARE(idx.data().toString(), QString("a"));
|
||||
|
||||
idx = model.index(1, static_cast<int>(Column::fileName));
|
||||
idx = model->index(1, static_cast<int>(Column::fileName));
|
||||
QCOMPARE(idx.data().toString(), QString("b"));
|
||||
|
||||
// File name should be updated instead of inserting a new file since the
|
||||
// resume file ID is the same
|
||||
file.fileName = "c";
|
||||
model.onFileUpdated(file);
|
||||
QCOMPARE(model.rowCount(), 2);
|
||||
model->onFileUpdated(file);
|
||||
QCOMPARE(model->rowCount(), 2);
|
||||
QCOMPARE(idx.data().toString(), QString("c"));
|
||||
}
|
||||
|
||||
|
@ -250,34 +243,32 @@ void TestFileTransferList::testFileRemoval()
|
|||
// Model should keep files in the list if they are finished, but not if they
|
||||
// were broken or canceled
|
||||
|
||||
Model model;
|
||||
|
||||
ToxFile file;
|
||||
file.fileKind = TOX_FILE_KIND_DATA;
|
||||
file.status = ToxFile::TRANSMITTING;
|
||||
model.onFileUpdated(file);
|
||||
model->onFileUpdated(file);
|
||||
|
||||
QCOMPARE(model.rowCount(), 1);
|
||||
QCOMPARE(model->rowCount(), 1);
|
||||
|
||||
file.status = ToxFile::BROKEN;
|
||||
model.onFileUpdated(file);
|
||||
QCOMPARE(model.rowCount(), 0);
|
||||
model->onFileUpdated(file);
|
||||
QCOMPARE(model->rowCount(), 0);
|
||||
|
||||
file.status = ToxFile::TRANSMITTING;
|
||||
model.onFileUpdated(file);
|
||||
QCOMPARE(model.rowCount(), 1);
|
||||
model->onFileUpdated(file);
|
||||
QCOMPARE(model->rowCount(), 1);
|
||||
|
||||
file.status = ToxFile::CANCELED;
|
||||
model.onFileUpdated(file);
|
||||
QCOMPARE(model.rowCount(), 0);
|
||||
model->onFileUpdated(file);
|
||||
QCOMPARE(model->rowCount(), 0);
|
||||
|
||||
file.status = ToxFile::TRANSMITTING;
|
||||
model.onFileUpdated(file);
|
||||
QCOMPARE(model.rowCount(), 1);
|
||||
model->onFileUpdated(file);
|
||||
QCOMPARE(model->rowCount(), 1);
|
||||
|
||||
file.status = ToxFile::FINISHED;
|
||||
model.onFileUpdated(file);
|
||||
QCOMPARE(model.rowCount(), 1);
|
||||
model->onFileUpdated(file);
|
||||
QCOMPARE(model->rowCount(), 1);
|
||||
}
|
||||
|
||||
QTEST_GUILESS_MAIN(TestFileTransferList)
|
||||
|
|
Loading…
Reference in New Issue
Block a user