mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Remove DocumentCache singleton
Leaf of our evil singleton tree.
This commit is contained in:
parent
0afc11fafc
commit
7d40bcf43d
|
@ -41,7 +41,8 @@
|
|||
#define TIME_COL_WIDTH 90.0
|
||||
|
||||
|
||||
ChatMessage::ChatMessage()
|
||||
ChatMessage::ChatMessage(DocumentCache& documentCache_)
|
||||
: documentCache{documentCache_}
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -49,9 +50,10 @@ ChatMessage::~ChatMessage() = default;
|
|||
|
||||
ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QString& rawMessage,
|
||||
MessageType type, bool isMe, MessageState state,
|
||||
const QDateTime& date, bool colorizeName)
|
||||
const QDateTime& date, DocumentCache& documentCache,
|
||||
bool colorizeName)
|
||||
{
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage);
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache));
|
||||
|
||||
QString text = rawMessage.toHtmlEscaped();
|
||||
QString senderText = sender;
|
||||
|
@ -108,16 +110,17 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
|
|||
}
|
||||
}
|
||||
|
||||
msg->addColumn(new Text(senderText, authorFont, true, sender, textType, color),
|
||||
msg->addColumn(new Text(documentCache, senderText, authorFont, true, sender, textType, color),
|
||||
ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
msg->addColumn(new Text(text, baseFont, false, ((type == ACTION) && isMe)
|
||||
msg->addColumn(new Text(documentCache, text, baseFont, false, ((type == ACTION) && isMe)
|
||||
? QString("%1 %2").arg(sender, rawMessage)
|
||||
: rawMessage),
|
||||
ColumnFormat(1.0, ColumnFormat::VariableSize));
|
||||
|
||||
switch (state) {
|
||||
case MessageState::complete:
|
||||
msg->addColumn(new Timestamp(date, Settings::getInstance().getTimestampFormat(), baseFont),
|
||||
msg->addColumn(new Timestamp(date, Settings::getInstance().getTimestampFormat(),
|
||||
baseFont, documentCache),
|
||||
ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
break;
|
||||
case MessageState::pending:
|
||||
|
@ -133,9 +136,10 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
|
|||
}
|
||||
|
||||
ChatMessage::Ptr ChatMessage::createChatInfoMessage(const QString& rawMessage,
|
||||
SystemMessageType type, const QDateTime& date)
|
||||
SystemMessageType type, const QDateTime& date,
|
||||
DocumentCache& documentCache)
|
||||
{
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage);
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache));
|
||||
QString text = rawMessage.toHtmlEscaped();
|
||||
|
||||
QString img;
|
||||
|
@ -155,18 +159,20 @@ ChatMessage::Ptr ChatMessage::createChatInfoMessage(const QString& rawMessage,
|
|||
|
||||
msg->addColumn(new Image(QSize(18, 18), img),
|
||||
ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
msg->addColumn(new Text("<b>" + text + "</b>", baseFont, false, text),
|
||||
msg->addColumn(new Text(documentCache, "<b>" + text + "</b>", baseFont, false, text),
|
||||
ColumnFormat(1.0, ColumnFormat::VariableSize, ColumnFormat::Left));
|
||||
msg->addColumn(new Timestamp(date, Settings::getInstance().getTimestampFormat(), baseFont),
|
||||
msg->addColumn(new Timestamp(date, Settings::getInstance().getTimestampFormat(),
|
||||
baseFont, documentCache),
|
||||
ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
ChatMessage::Ptr ChatMessage::createFileTransferMessage(const QString& sender, CoreFile& coreFile,
|
||||
ToxFile file, bool isMe, const QDateTime& date)
|
||||
ToxFile file, bool isMe, const QDateTime& date,
|
||||
DocumentCache& documentCache)
|
||||
{
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage);
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache));
|
||||
|
||||
QFont baseFont = Settings::getInstance().getChatMessageFont();
|
||||
QFont authorFont = baseFont;
|
||||
|
@ -174,19 +180,19 @@ ChatMessage::Ptr ChatMessage::createFileTransferMessage(const QString& sender, C
|
|||
authorFont.setBold(true);
|
||||
}
|
||||
|
||||
msg->addColumn(new Text(sender, authorFont, true),
|
||||
msg->addColumn(new Text(documentCache, sender, authorFont, true),
|
||||
ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
msg->addColumn(new ChatLineContentProxy(new FileTransferWidget(nullptr, coreFile, file), 320, 0.6f),
|
||||
ColumnFormat(1.0, ColumnFormat::VariableSize));
|
||||
msg->addColumn(new Timestamp(date, Settings::getInstance().getTimestampFormat(), baseFont),
|
||||
msg->addColumn(new Timestamp(date, Settings::getInstance().getTimestampFormat(), baseFont, documentCache),
|
||||
ColumnFormat(TIME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
ChatMessage::Ptr ChatMessage::createTypingNotification()
|
||||
ChatMessage::Ptr ChatMessage::createTypingNotification(DocumentCache& documentCache)
|
||||
{
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage);
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache));
|
||||
|
||||
QFont baseFont = Settings::getInstance().getChatMessageFont();
|
||||
|
||||
|
@ -199,7 +205,7 @@ ChatMessage::Ptr ChatMessage::createTypingNotification()
|
|||
// as user will keep typing. Issue #1280
|
||||
msg->addColumn(new NotificationIcon(QSize(18, 18)),
|
||||
ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
msg->addColumn(new Text("[user]...", baseFont, false, ""),
|
||||
msg->addColumn(new Text(documentCache, "[user]...", baseFont, false, ""),
|
||||
ColumnFormat(1.0, ColumnFormat::VariableSize, ColumnFormat::Left));
|
||||
|
||||
return msg;
|
||||
|
@ -213,14 +219,14 @@ ChatMessage::Ptr ChatMessage::createTypingNotification()
|
|||
*
|
||||
* @return created message
|
||||
*/
|
||||
ChatMessage::Ptr ChatMessage::createBusyNotification()
|
||||
ChatMessage::Ptr ChatMessage::createBusyNotification(DocumentCache& documentCache)
|
||||
{
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage);
|
||||
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage(documentCache));
|
||||
QFont baseFont = Settings::getInstance().getChatMessageFont();
|
||||
baseFont.setPixelSize(baseFont.pixelSize() + 2);
|
||||
baseFont.setBold(true);
|
||||
|
||||
msg->addColumn(new Text(QObject::tr("Reformatting text...", "Waiting for text to be reformatted"), baseFont, false, ""),
|
||||
msg->addColumn(new Text(documentCache, QObject::tr("Reformatting text...", "Waiting for text to be reformatted"), baseFont, false, ""),
|
||||
ColumnFormat(1.0, ColumnFormat::VariableSize, ColumnFormat::Center));
|
||||
|
||||
return msg;
|
||||
|
@ -231,7 +237,7 @@ void ChatMessage::markAsDelivered(const QDateTime& time)
|
|||
QFont baseFont = Settings::getInstance().getChatMessageFont();
|
||||
|
||||
// remove the spinner and replace it by $time
|
||||
replaceContent(2, new Timestamp(time, Settings::getInstance().getTimestampFormat(), baseFont));
|
||||
replaceContent(2, new Timestamp(time, Settings::getInstance().getTimestampFormat(), baseFont, documentCache));
|
||||
}
|
||||
|
||||
void ChatMessage::markAsBroken()
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
class CoreFile;
|
||||
class QGraphicsScene;
|
||||
class DocumentCache;
|
||||
|
||||
class ChatMessage : public ChatLine
|
||||
{
|
||||
|
@ -47,21 +48,22 @@ public:
|
|||
ALERT,
|
||||
};
|
||||
|
||||
ChatMessage();
|
||||
explicit ChatMessage(DocumentCache& documentCache);
|
||||
~ChatMessage();
|
||||
ChatMessage(const ChatMessage&) = default;
|
||||
ChatMessage& operator=(const ChatMessage&) = default;
|
||||
ChatMessage(ChatMessage&&) = default;
|
||||
|
||||
static ChatMessage::Ptr createChatMessage(const QString& sender, const QString& rawMessage,
|
||||
MessageType type, bool isMe, MessageState state,
|
||||
const QDateTime& date, bool colorizeName = false);
|
||||
const QDateTime& date, DocumentCache&,
|
||||
bool colorizeName = false);
|
||||
static ChatMessage::Ptr createChatInfoMessage(const QString& rawMessage, SystemMessageType type,
|
||||
const QDateTime& date);
|
||||
const QDateTime& date, DocumentCache&);
|
||||
static ChatMessage::Ptr createFileTransferMessage(const QString& sender, CoreFile& coreFile,
|
||||
ToxFile file, bool isMe, const QDateTime& date);
|
||||
static ChatMessage::Ptr createTypingNotification();
|
||||
static ChatMessage::Ptr createBusyNotification();
|
||||
ToxFile file, bool isMe, const QDateTime& date,
|
||||
DocumentCache&);
|
||||
static ChatMessage::Ptr createTypingNotification(DocumentCache&);
|
||||
static ChatMessage::Ptr createBusyNotification(DocumentCache&);
|
||||
|
||||
void markAsDelivered(const QDateTime& time);
|
||||
void markAsBroken();
|
||||
|
@ -77,4 +79,5 @@ protected:
|
|||
|
||||
private:
|
||||
bool action = false;
|
||||
DocumentCache& documentCache;
|
||||
};
|
||||
|
|
|
@ -62,16 +62,16 @@ T clamp(T x, T min, T max)
|
|||
return x;
|
||||
}
|
||||
|
||||
ChatMessage::Ptr createDateMessage(QDateTime timestamp)
|
||||
ChatMessage::Ptr createDateMessage(QDateTime timestamp, DocumentCache& documentCache)
|
||||
{
|
||||
const auto& s = Settings::getInstance();
|
||||
const auto date = timestamp.date();
|
||||
auto dateText = date.toString(s.getDateFormat());
|
||||
return ChatMessage::createChatInfoMessage(dateText, ChatMessage::INFO, QDateTime());
|
||||
return ChatMessage::createChatInfoMessage(dateText, ChatMessage::INFO, QDateTime(), documentCache);
|
||||
}
|
||||
|
||||
ChatMessage::Ptr createMessage(const QString& displayName, bool isSelf, bool colorizeNames,
|
||||
const ChatLogMessage& chatLogMessage)
|
||||
const ChatLogMessage& chatLogMessage, DocumentCache& documentCache)
|
||||
{
|
||||
auto messageType = chatLogMessage.message.isAction ? ChatMessage::MessageType::ACTION
|
||||
: ChatMessage::MessageType::NORMAL;
|
||||
|
@ -88,11 +88,13 @@ ChatMessage::Ptr createMessage(const QString& displayName, bool isSelf, bool col
|
|||
|
||||
const auto timestamp = chatLogMessage.message.timestamp;
|
||||
return ChatMessage::createChatMessage(displayName, chatLogMessage.message.content, messageType,
|
||||
isSelf, chatLogMessage.state, timestamp, colorizeNames);
|
||||
isSelf, chatLogMessage.state, timestamp, documentCache,
|
||||
colorizeNames);
|
||||
}
|
||||
|
||||
void renderMessageRaw(const QString& displayName, bool isSelf, bool colorizeNames,
|
||||
const ChatLogMessage& chatLogMessage, ChatLine::Ptr& chatLine)
|
||||
const ChatLogMessage& chatLogMessage, ChatLine::Ptr& chatLine,
|
||||
DocumentCache& documentCache)
|
||||
{
|
||||
// HACK: This is kind of gross, but there's not an easy way to fit this into
|
||||
// the existing architecture. This shouldn't ever fail since we should only
|
||||
|
@ -108,7 +110,7 @@ void renderMessageRaw(const QString& displayName, bool isSelf, bool colorizeName
|
|||
chatMessage->markAsBroken();
|
||||
}
|
||||
} else {
|
||||
chatLine = createMessage(displayName, isSelf, colorizeNames, chatLogMessage);
|
||||
chatLine = createMessage(displayName, isSelf, colorizeNames, chatLogMessage, documentCache);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -204,11 +206,13 @@ ChatLogIdx clampedAdd(ChatLogIdx idx, int val, IChatLog& chatLog)
|
|||
} // namespace
|
||||
|
||||
|
||||
ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, QWidget* parent)
|
||||
ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache& documentCache_,
|
||||
QWidget* parent)
|
||||
: QGraphicsView(parent)
|
||||
, chatLog(chatLog_)
|
||||
, core(core_)
|
||||
, chatLineStorage(new ChatLineStorage())
|
||||
, documentCache(documentCache_)
|
||||
{
|
||||
// Create the scene
|
||||
busyScene = new QGraphicsScene(this);
|
||||
|
@ -216,7 +220,7 @@ ChatWidget::ChatWidget(IChatLog& chatLog_, const Core& core_, QWidget* parent)
|
|||
scene->setItemIndexMethod(QGraphicsScene::BspTreeIndex);
|
||||
setScene(scene);
|
||||
|
||||
busyNotification = ChatMessage::createBusyNotification();
|
||||
busyNotification = ChatMessage::createBusyNotification(documentCache);
|
||||
busyNotification->addToScene(busyScene);
|
||||
busyNotification->visibilityChanged(true);
|
||||
|
||||
|
@ -539,7 +543,7 @@ void ChatWidget::insertChatlines(std::map<ChatLogIdx, ChatLine::Ptr> chatLines)
|
|||
if (!chatLineStorage->contains(date)) {
|
||||
// If there is no dateline for the given date we need to insert it
|
||||
// above the line we'd like to insert.
|
||||
auto dateLine = createDateMessage(date);
|
||||
auto dateLine = createDateMessage(date, documentCache);
|
||||
chatLineStorage->insertDateLine(date, dateLine);
|
||||
dateLine->addToScene(scene);
|
||||
dateLine->visibilityChanged(false);
|
||||
|
@ -1391,7 +1395,7 @@ bool ChatWidget::isActiveFileTransfer(ChatLine::Ptr l)
|
|||
|
||||
void ChatWidget::setTypingNotification()
|
||||
{
|
||||
typingNotification = ChatMessage::createTypingNotification();
|
||||
typingNotification = ChatMessage::createTypingNotification(documentCache);
|
||||
typingNotification->visibilityChanged(true);
|
||||
typingNotification->setVisible(false);
|
||||
typingNotification->addToScene(scene);
|
||||
|
@ -1409,7 +1413,8 @@ void ChatWidget::renderItem(const ChatLogItem& item, bool hideName, bool coloriz
|
|||
case ChatLogItem::ContentType::message: {
|
||||
const auto& chatLogMessage = item.getContentAsMessage();
|
||||
|
||||
renderMessageRaw(item.getDisplayName(), isSelf, colorizeNames_, chatLogMessage, chatMessage);
|
||||
renderMessageRaw(item.getDisplayName(), isSelf, colorizeNames_, chatLogMessage,
|
||||
chatMessage, documentCache);
|
||||
|
||||
break;
|
||||
}
|
||||
|
@ -1422,7 +1427,8 @@ void ChatWidget::renderItem(const ChatLogItem& item, bool hideName, bool coloriz
|
|||
const auto& systemMessage = item.getContentAsSystemMessage();
|
||||
|
||||
auto chatMessageType = getChatMessageType(systemMessage);
|
||||
chatMessage = ChatMessage::createChatInfoMessage(systemMessage.toString(), chatMessageType, QDateTime::currentDateTime());
|
||||
chatMessage = ChatMessage::createChatInfoMessage(systemMessage.toString(),
|
||||
chatMessageType, QDateTime::currentDateTime(), documentCache);
|
||||
// Ignore caller's decision to hide the name. We show the icon in the
|
||||
// slot of the sender's name so we always want it visible
|
||||
hideName = false;
|
||||
|
@ -1441,7 +1447,8 @@ void ChatWidget::renderFile(QString displayName, ToxFile file, bool isSelf, QDat
|
|||
if (!chatMessage) {
|
||||
CoreFile* coreFile = core.getCoreFile();
|
||||
assert(coreFile);
|
||||
chatMessage = ChatMessage::createFileTransferMessage(displayName, *coreFile, file, isSelf, timestamp);
|
||||
chatMessage = ChatMessage::createFileTransferMessage(displayName, *coreFile,
|
||||
file, isSelf, timestamp, documentCache);
|
||||
} else {
|
||||
auto proxy = static_cast<ChatLineContentProxy*>(chatMessage->getContent(1));
|
||||
assert(proxy->getWidgetType() == ChatLineContentProxy::FileTransferWidgetType);
|
||||
|
|
|
@ -42,7 +42,8 @@ class ChatWidget : public QGraphicsView
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ChatWidget(IChatLog& chatLog_, const Core& core_, QWidget* parent = nullptr);
|
||||
ChatWidget(IChatLog& chatLog_, const Core& core_, DocumentCache&,
|
||||
QWidget* parent = nullptr);
|
||||
virtual ~ChatWidget();
|
||||
|
||||
void insertChatlines(std::map<ChatLogIdx, ChatLine::Ptr> chatLines);
|
||||
|
@ -214,4 +215,5 @@ private:
|
|||
std::unique_ptr<ChatLineStorage> chatLineStorage;
|
||||
|
||||
std::vector<std::function<void(void)>> renderCompletionFns;
|
||||
DocumentCache& documentCache;
|
||||
};
|
||||
|
|
|
@ -31,14 +31,16 @@
|
|||
#include <QTextBlock>
|
||||
#include <QTextFragment>
|
||||
|
||||
Text::Text(const QString& txt, const QFont& font, bool enableElide, const QString& rwText,
|
||||
const TextType& type, const QColor& custom)
|
||||
Text::Text(DocumentCache& documentCache_, const QString& txt, const QFont& font,
|
||||
bool enableElide, const QString& rwText, const TextType& type,
|
||||
const QColor& custom)
|
||||
: rawText(rwText)
|
||||
, elide(enableElide)
|
||||
, defFont(font)
|
||||
, defStyleSheet(Style::getStylesheet(QStringLiteral("chatArea/innerStyle.css"), font))
|
||||
, textType(type)
|
||||
, customColor(custom)
|
||||
, documentCache(documentCache_)
|
||||
{
|
||||
color = textColor();
|
||||
setText(txt);
|
||||
|
@ -49,7 +51,7 @@ Text::Text(const QString& txt, const QFont& font, bool enableElide, const QStrin
|
|||
Text::~Text()
|
||||
{
|
||||
if (doc)
|
||||
DocumentCache::getInstance().push(doc);
|
||||
documentCache.push(doc);
|
||||
}
|
||||
|
||||
void Text::setText(const QString& txt)
|
||||
|
@ -315,7 +317,7 @@ QString Text::getLinkAt(QPointF scenePos) const
|
|||
void Text::regenerate()
|
||||
{
|
||||
if (!doc) {
|
||||
doc = DocumentCache::getInstance().pop();
|
||||
doc = documentCache.pop();
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
|
@ -362,7 +364,7 @@ void Text::regenerate()
|
|||
|
||||
void Text::freeResources()
|
||||
{
|
||||
DocumentCache::getInstance().push(doc);
|
||||
documentCache.push(doc);
|
||||
doc = nullptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include <QFont>
|
||||
|
||||
class QTextDocument;
|
||||
class DocumentCache;
|
||||
|
||||
class Text : public ChatLineContent
|
||||
{
|
||||
|
@ -38,8 +39,10 @@ public:
|
|||
CUSTOM
|
||||
};
|
||||
|
||||
Text(const QString& txt = "", const QFont& font = QFont(), bool enableElide = false,
|
||||
const QString& rawText = QString(), const TextType& type = NORMAL, const QColor& custom = Style::getColor(Style::MainText));
|
||||
Text(DocumentCache&, const QString& txt = "", const QFont& font = QFont(),
|
||||
bool enableElide = false, const QString& rawText = QString(),
|
||||
const TextType& type = NORMAL,
|
||||
const QColor& custom = Style::getColor(Style::MainText));
|
||||
virtual ~Text();
|
||||
|
||||
void setText(const QString& txt);
|
||||
|
@ -109,4 +112,5 @@ private:
|
|||
TextType textType;
|
||||
QColor color;
|
||||
QColor customColor;
|
||||
DocumentCache& documentCache;
|
||||
};
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
|
||||
#include "timestamp.h"
|
||||
|
||||
Timestamp::Timestamp(const QDateTime& time_, const QString& format, const QFont& font)
|
||||
: Text(time_.toString(format), font, false, time_.toString(format))
|
||||
Timestamp::Timestamp(const QDateTime& time_, const QString& format, const QFont& font, DocumentCache& documentCache_)
|
||||
: Text(documentCache_, time_.toString(format), font, false, time_.toString(format))
|
||||
{
|
||||
time = time_;
|
||||
}
|
||||
|
|
|
@ -24,12 +24,14 @@
|
|||
#include <QTextDocument>
|
||||
|
||||
class QTextDocument;
|
||||
class DocumentCache;
|
||||
|
||||
class Timestamp : public Text
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
Timestamp(const QDateTime& time_, const QString& format, const QFont& font);
|
||||
Timestamp(const QDateTime& time_, const QString& format, const QFont& font,
|
||||
DocumentCache&);
|
||||
QDateTime getTime();
|
||||
|
||||
protected:
|
||||
|
|
|
@ -41,12 +41,3 @@ void DocumentCache::push(QTextDocument* doc)
|
|||
documents.push(doc);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the singleton instance.
|
||||
*/
|
||||
DocumentCache& DocumentCache::getInstance()
|
||||
{
|
||||
static DocumentCache instance;
|
||||
return instance;
|
||||
}
|
||||
|
|
|
@ -26,17 +26,13 @@ class QTextDocument;
|
|||
class DocumentCache
|
||||
{
|
||||
public:
|
||||
static DocumentCache& getInstance();
|
||||
|
||||
QTextDocument* pop();
|
||||
void push(QTextDocument* doc);
|
||||
|
||||
private:
|
||||
DocumentCache() = default;
|
||||
~DocumentCache();
|
||||
DocumentCache(DocumentCache&) = delete;
|
||||
DocumentCache& operator=(const DocumentCache&) = delete;
|
||||
|
||||
QTextDocument* pop();
|
||||
void push(QTextDocument* doc);
|
||||
private:
|
||||
QStack<QTextDocument*> documents;
|
||||
};
|
||||
|
|
|
@ -106,8 +106,10 @@ QString secondsToDHMS(quint32 duration)
|
|||
}
|
||||
} // namespace
|
||||
|
||||
ChatForm::ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_, IMessageDispatcher& messageDispatcher_)
|
||||
: GenericChatForm(profile.getCore(), chatFriend, chatLog_, messageDispatcher_)
|
||||
ChatForm::ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache_)
|
||||
: GenericChatForm(profile.getCore(), chatFriend, chatLog_, messageDispatcher_,
|
||||
documentCache_)
|
||||
, core{profile.getCore()}
|
||||
, f(chatFriend)
|
||||
, isTyping{false}
|
||||
|
|
|
@ -42,12 +42,14 @@ class QPixmap;
|
|||
class QHideEvent;
|
||||
class QMoveEvent;
|
||||
class ImagePreviewButton;
|
||||
class DocumentCache;
|
||||
|
||||
class ChatForm : public GenericChatForm
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_, IMessageDispatcher& messageDispatcher_);
|
||||
ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, DocumentCache&);
|
||||
~ChatForm() override;
|
||||
void setStatusMessage(const QString& newMessage);
|
||||
|
||||
|
|
|
@ -137,7 +137,8 @@ QPushButton* createButton(const QString& name, T* self, Fun onClickSlot)
|
|||
} // namespace
|
||||
|
||||
GenericChatForm::GenericChatForm(const Core& core_, const Contact* contact, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, QWidget* parent_)
|
||||
IMessageDispatcher& messageDispatcher_, DocumentCache& documentCache,
|
||||
QWidget* parent_)
|
||||
: QWidget(parent_, Qt::Window)
|
||||
, core{core_}
|
||||
, audioInputFlag(false)
|
||||
|
@ -149,7 +150,7 @@ GenericChatForm::GenericChatForm(const Core& core_, const Contact* contact, ICha
|
|||
headWidget = new ChatFormHeader();
|
||||
searchForm = new SearchForm();
|
||||
dateInfo = new QLabel(this);
|
||||
chatWidget = new ChatWidget(chatLog_, core, this);
|
||||
chatWidget = new ChatWidget(chatLog_, core, documentCache, this);
|
||||
searchForm->hide();
|
||||
dateInfo->setAlignment(Qt::AlignHCenter);
|
||||
dateInfo->setVisible(false);
|
||||
|
|
|
@ -53,6 +53,7 @@ class QVBoxLayout;
|
|||
|
||||
class IMessageDispatcher;
|
||||
struct Message;
|
||||
class DocumentCache;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
|
@ -69,7 +70,8 @@ class GenericChatForm : public QWidget
|
|||
Q_OBJECT
|
||||
public:
|
||||
GenericChatForm(const Core& core_, const Contact* contact, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, QWidget* parent_ = nullptr);
|
||||
IMessageDispatcher& messageDispatcher_, DocumentCache&,
|
||||
QWidget* parent_ = nullptr);
|
||||
~GenericChatForm() override;
|
||||
|
||||
void setName(const QString& newName);
|
||||
|
|
|
@ -82,8 +82,9 @@ QString editName(const QString& name)
|
|||
* @brief Timeout = peer stopped sending audio.
|
||||
*/
|
||||
|
||||
GroupChatForm::GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_, IMessageDispatcher& messageDispatcher_, IGroupSettings& settings_)
|
||||
: GenericChatForm(core_, chatGroup, chatLog_, messageDispatcher_)
|
||||
GroupChatForm::GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, IGroupSettings& settings_, DocumentCache& documentCache_)
|
||||
: GenericChatForm(core_, chatGroup, chatLog_, messageDispatcher_, documentCache_)
|
||||
, core{core_}
|
||||
, group(chatGroup)
|
||||
, inCall(false)
|
||||
|
|
|
@ -35,12 +35,15 @@ class IMessageDispatcher;
|
|||
struct Message;
|
||||
class Settings;
|
||||
class IGroupSettings;
|
||||
class DocumentCache;
|
||||
|
||||
class GroupChatForm : public GenericChatForm
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_, IMessageDispatcher& messageDispatcher_, IGroupSettings& settings_);
|
||||
explicit GroupChatForm(Core& core_, Group* chatGroup, IChatLog& chatLog_,
|
||||
IMessageDispatcher& messageDispatcher_, IGroupSettings& settings_,
|
||||
DocumentCache&);
|
||||
~GroupChatForm();
|
||||
|
||||
void peerAudioPlaying(ToxPk peerPk);
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include "splitterrestorer.h"
|
||||
#include "form/groupchatform.h"
|
||||
#include "src/chatlog/content/filetransferwidget.h"
|
||||
#include "src/chatlog/documentcache.h"
|
||||
#include "src/core/core.h"
|
||||
#include "src/core/coreav.h"
|
||||
#include "src/core/corefile.h"
|
||||
|
@ -147,6 +148,7 @@ Widget::Widget(Profile &profile_, IAudioControl& audio_, QWidget* parent)
|
|||
, eventIcon(false)
|
||||
, audio(audio_)
|
||||
, settings(Settings::getInstance())
|
||||
, documentCache(new DocumentCache())
|
||||
{
|
||||
installEventFilter(this);
|
||||
QString locale = settings.getTranslation();
|
||||
|
@ -1185,7 +1187,8 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
|
|||
auto chatHistory =
|
||||
std::make_shared<ChatHistory>(*newfriend, history, *core, settings,
|
||||
*friendMessageDispatcher);
|
||||
auto friendForm = new ChatForm(profile, newfriend, *chatHistory, *friendMessageDispatcher);
|
||||
auto friendForm = new ChatForm(profile, newfriend, *chatHistory,
|
||||
*friendMessageDispatcher, *documentCache);
|
||||
connect(friendForm, &ChatForm::updateFriendActivity, this, &Widget::updateFriendActivity);
|
||||
|
||||
friendMessageDispatchers[friendPk] = friendMessageDispatcher;
|
||||
|
@ -2168,7 +2171,7 @@ Group* Widget::createGroup(uint32_t groupnumber, const GroupId& groupId)
|
|||
connect(messageDispatcher.get(), &IMessageDispatcher::messageReceived, notifyReceivedCallback);
|
||||
groupAlertConnections.insert(groupId, notifyReceivedConnection);
|
||||
|
||||
auto form = new GroupChatForm(*core, newgroup, *groupChatLog, *messageDispatcher, settings);
|
||||
auto form = new GroupChatForm(*core, newgroup, *groupChatLog, *messageDispatcher, settings, *documentCache);
|
||||
connect(&settings, &Settings::nameColorsChanged, form, &GenericChatForm::setColorizedNames);
|
||||
form->setColorizedNames(settings.getEnableGroupChatsColor());
|
||||
groupMessageDispatchers[groupId] = messageDispatcher;
|
||||
|
|
|
@ -83,6 +83,7 @@ class UpdateCheck;
|
|||
class Settings;
|
||||
class IChatLog;
|
||||
class ChatHistory;
|
||||
class DocumentCache;
|
||||
|
||||
class Widget final : public QMainWindow
|
||||
{
|
||||
|
@ -381,6 +382,7 @@ private:
|
|||
QAction* nextConversationAction;
|
||||
QAction* previousConversationAction;
|
||||
#endif
|
||||
std::unique_ptr<DocumentCache> documentCache;
|
||||
};
|
||||
|
||||
bool toxActivateEventHandler(const QByteArray& data);
|
||||
|
|
Loading…
Reference in New Issue
Block a user