mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
filling the gaps
This commit is contained in:
parent
380d7b9a07
commit
3190530686
|
@ -61,6 +61,14 @@ int ChatLine::getRowIndex() const
|
|||
return rowIndex;
|
||||
}
|
||||
|
||||
ChatLineContent *ChatLine::getContent(int col) const
|
||||
{
|
||||
if(col < content.size() && col >= 0)
|
||||
return content[col];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void ChatLine::selectionCleared()
|
||||
{
|
||||
for(ChatLineContent* c : content)
|
||||
|
|
|
@ -72,6 +72,7 @@ public:
|
|||
|
||||
int getColumnCount();
|
||||
int getRowIndex() const;
|
||||
ChatLineContent* getContent(int col) const;
|
||||
|
||||
bool isOverSelection(QPointF scenePos);
|
||||
|
||||
|
|
|
@ -96,6 +96,26 @@ ChatMessage* ChatLog::addChatMessage(const QString& sender, const QString& msg,
|
|||
return line;
|
||||
}
|
||||
|
||||
ChatMessage *ChatLog::addChatAction(const QString &sender, const QString &msg, const QDateTime ×tamp)
|
||||
{
|
||||
ChatMessage* line = addChatAction(sender, msg);
|
||||
line->markAsSent(timestamp);
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
ChatMessage *ChatLog::addChatAction(const QString &sender, const QString &msg)
|
||||
{
|
||||
ChatMessage* line = new ChatMessage(scene, msg);
|
||||
line->addColumn(new Text("", Style::getFont(Style::Medium), true), ColumnFormat(75.0, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
line->addColumn(new Text("<font color=\"red\">*" + sender + " " + SmileyPack::getInstance().smileyfied(msg) + "</font>"), ColumnFormat(1.0, ColumnFormat::VariableSize));
|
||||
line->addColumn(new Spinner(QSizeF(16, 16)), ColumnFormat(50.0, ColumnFormat::FixedSize, ColumnFormat::Right));
|
||||
line->setAsAction();
|
||||
|
||||
insertChatline(line);
|
||||
return line;
|
||||
}
|
||||
|
||||
ChatMessage *ChatLog::addSystemMessage(const QString &msg, const QDateTime& timestamp)
|
||||
{
|
||||
ChatMessage* line = new ChatMessage(scene, msg);
|
||||
|
@ -435,6 +455,11 @@ QString ChatLog::getSelectedText() const
|
|||
return QString();
|
||||
}
|
||||
|
||||
bool ChatLog::isEmpty() const
|
||||
{
|
||||
return lines.isEmpty();
|
||||
}
|
||||
|
||||
void ChatLog::showContextMenu(const QPoint& globalPos, const QPointF& scenePos)
|
||||
{
|
||||
QMenu menu;
|
||||
|
|
|
@ -37,6 +37,8 @@ public:
|
|||
|
||||
ChatMessage* addChatMessage(const QString& sender, const QString& msg, const QDateTime& timestamp, bool self);
|
||||
ChatMessage* addChatMessage(const QString& sender, const QString& msg, bool self);
|
||||
ChatMessage* addChatAction(const QString& sender, const QString& msg, const QDateTime& timestamp);
|
||||
ChatMessage* addChatAction(const QString& sender, const QString& msg);
|
||||
|
||||
ChatMessage* addSystemMessage(const QString& msg, const QDateTime& timestamp);
|
||||
ChatMessage* addFileTransferMessage(const QString& sender, const ToxFile& file, const QDateTime ×tamp, bool self);
|
||||
|
@ -48,6 +50,8 @@ public:
|
|||
void copySelectedText() const;
|
||||
QString getSelectedText() const;
|
||||
|
||||
bool isEmpty() const;
|
||||
|
||||
protected:
|
||||
QRect getVisibleRect() const;
|
||||
ChatLineContent* getContentFromPos(QPointF scenePos) const;
|
||||
|
|
|
@ -37,3 +37,13 @@ QString ChatMessage::toString() const
|
|||
{
|
||||
return rawString;
|
||||
}
|
||||
|
||||
bool ChatMessage::isAction() const
|
||||
{
|
||||
return action;
|
||||
}
|
||||
|
||||
void ChatMessage::setAsAction()
|
||||
{
|
||||
action = true;
|
||||
}
|
||||
|
|
|
@ -28,10 +28,13 @@ public:
|
|||
|
||||
void markAsSent(const QDateTime& time);
|
||||
QString toString() const;
|
||||
bool isAction() const;
|
||||
void setAsAction();
|
||||
|
||||
private:
|
||||
ChatLineContent* midColumn = nullptr;
|
||||
QString rawString;
|
||||
bool action = false;
|
||||
};
|
||||
|
||||
#endif // CHATMESSAGE_H
|
||||
|
|
|
@ -69,6 +69,21 @@ FileTransferWidget::~FileTransferWidget()
|
|||
delete ui;
|
||||
}
|
||||
|
||||
void FileTransferWidget::acceptTransfer(const QString &path)
|
||||
{
|
||||
if(!QFileInfo(QDir(path).path()).isWritable())
|
||||
{
|
||||
QMessageBox::warning(0,
|
||||
tr("Location not writable","Title of permissions popup"),
|
||||
tr("You do not have permission to write that location. Choose another, or cancel the save dialog.", "text of permissions popup"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!path.isEmpty())
|
||||
Core::getInstance()->acceptFileRecvRequest(fileInfo.friendId, fileInfo.fileNum, path);
|
||||
}
|
||||
|
||||
void FileTransferWidget::onFileTransferInfo(ToxFile file)
|
||||
{
|
||||
if(fileInfo != file)
|
||||
|
@ -255,18 +270,7 @@ void FileTransferWidget::handleButton(QPushButton *btn)
|
|||
if(btn->objectName() == "accept")
|
||||
{
|
||||
QString path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(fileInfo.fileName));
|
||||
|
||||
if(!QFileInfo(QDir(path).path()).isWritable())
|
||||
{
|
||||
QMessageBox::warning(0,
|
||||
tr("Location not writable","Title of permissions popup"),
|
||||
tr("You do not have permission to write that location. Choose another, or cancel the save dialog.", "text of permissions popup"));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!path.isEmpty())
|
||||
Core::getInstance()->acceptFileRecvRequest(fileInfo.friendId, fileInfo.fileNum, path);
|
||||
acceptTransfer(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ public:
|
|||
explicit FileTransferWidget(QWidget *parent, ToxFile file);
|
||||
virtual ~FileTransferWidget();
|
||||
|
||||
void acceptTransfer(const QString& path);
|
||||
|
||||
protected slots:
|
||||
void onFileTransferInfo(ToxFile file);
|
||||
void onFileTransferAccepted(ToxFile file);
|
||||
|
|
|
@ -1054,7 +1054,7 @@ void Core::setAvatar(uint8_t format, const QByteArray& data)
|
|||
|
||||
ToxID Core::getSelfId() const
|
||||
{
|
||||
uint8_t friendAddress[TOX_FRIEND_ADDRESS_SIZE];
|
||||
uint8_t friendAddress[TOX_FRIEND_ADDRESS_SIZE] = {0};
|
||||
tox_get_address(tox, friendAddress);
|
||||
return ToxID::fromString(CFriendAddress::toString(friendAddress));
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
#include "src/misc/settings.h"
|
||||
#include "src/misc/cstring.h"
|
||||
#include "src/chatlog/chatmessage.h"
|
||||
#include "src/chatlog/content/filetransferwidget.h"
|
||||
|
||||
ChatForm::ChatForm(Friend* chatFriend)
|
||||
: f(chatFriend)
|
||||
|
@ -74,7 +75,6 @@ ChatForm::ChatForm(Friend* chatFriend)
|
|||
connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered);
|
||||
connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle()));
|
||||
connect(volButton, SIGNAL(clicked()), this, SLOT(onVolMuteToggle()));
|
||||
//TODO: connect(chatWidget, &ChatAreaWidget::onFileTranfertInterract, this, &ChatForm::onFileTansBtnClicked);
|
||||
connect(Core::getInstance(), &Core::fileSendFailed, this, &ChatForm::onFileSendFailed);
|
||||
connect(this, SIGNAL(chatAreaCleared()), this, SLOT(clearReciepts()));
|
||||
|
||||
|
@ -197,11 +197,14 @@ void ChatForm::onFileRecvRequest(ToxFile file)
|
|||
previousId = friendId;
|
||||
}
|
||||
|
||||
chatWidget->addFileTransferMessage(name, file, QDateTime::currentDateTime(), false);
|
||||
//TODO:
|
||||
// if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty()
|
||||
// || Settings::getInstance().getAutoSaveEnabled())
|
||||
// fileTrans->pressFromHtml("btnB");
|
||||
ChatMessage* msg = chatWidget->addFileTransferMessage(name, file, QDateTime::currentDateTime(), false);
|
||||
if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty()
|
||||
|| Settings::getInstance().getAutoSaveEnabled())
|
||||
{
|
||||
FileTransferWidget* tfWidget = dynamic_cast<FileTransferWidget*>(msg->getContent(1));
|
||||
if(tfWidget)
|
||||
tfWidget->acceptTransfer(Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())));
|
||||
}
|
||||
}
|
||||
|
||||
void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
|
||||
|
@ -230,7 +233,7 @@ void ChatForm::onAvInvite(int FriendId, int CallId, bool video)
|
|||
connect(callButton, SIGNAL(clicked()), this, SLOT(onAnswerCallTriggered()));
|
||||
}
|
||||
|
||||
//TODO: addSystemInfoMessage(tr("%1 calling").arg(f->getDisplayedName()), "white", QDateTime::currentDateTime());
|
||||
chatWidget->addSystemMessage(tr("%1 calling").arg(f->getDisplayedName()), QDateTime::currentDateTime());
|
||||
|
||||
Widget* w = Widget::getInstance();
|
||||
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow())
|
||||
|
@ -496,7 +499,7 @@ void ChatForm::onAvRejected(int FriendId, int)
|
|||
connect(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
|
||||
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
|
||||
|
||||
//TODO: addSystemInfoMessage(tr("Call rejected"), "white", QDateTime::currentDateTime());
|
||||
chatWidget->addSystemMessage(tr("Call rejected"), QDateTime::currentDateTime());
|
||||
|
||||
netcam->hide();
|
||||
}
|
||||
|
@ -630,18 +633,6 @@ void ChatForm::onVolMuteToggle()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void ChatForm::onFileTansBtnClicked(QString widgetName, QString buttonName)
|
||||
{
|
||||
uint id = widgetName.toUInt();
|
||||
|
||||
auto it = ftransWidgets.find(id);
|
||||
if (it != ftransWidgets.end())
|
||||
it.value()->pressFromHtml(buttonName);
|
||||
else
|
||||
qDebug() << "no filetransferwidget: " << id;
|
||||
}
|
||||
|
||||
void ChatForm::onFileSendFailed(int FriendId, const QString &fname)
|
||||
{
|
||||
if (FriendId != f->getFriendID())
|
||||
|
@ -708,39 +699,39 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
|
|||
|
||||
ToxID storedPrevId;
|
||||
std::swap(storedPrevId, previousId);
|
||||
// QList<ChatMessage*> historyMessages;
|
||||
QList<ChatMessage*> historyMessages;
|
||||
|
||||
// QDate lastDate(1,0,0);
|
||||
// for (const auto &it : msgs)
|
||||
// {
|
||||
// // Show the date every new day
|
||||
// QDateTime msgDateTime = it.timestamp.toLocalTime();
|
||||
// QDate msgDate = msgDateTime.date();
|
||||
// if (msgDate > lastDate)
|
||||
// {
|
||||
// lastDate = msgDate;
|
||||
// //TODO: historyMessages.append(genSystemInfoAction(msgDate.toString(),"",QDateTime()));
|
||||
// }
|
||||
//TODO: possibly broken
|
||||
QDate lastDate(1,0,0);
|
||||
for (const auto &it : msgs)
|
||||
{
|
||||
// Show the date every new day
|
||||
QDateTime msgDateTime = it.timestamp.toLocalTime();
|
||||
QDate msgDate = msgDateTime.date();
|
||||
if (msgDate > lastDate)
|
||||
{
|
||||
lastDate = msgDate;
|
||||
chatWidget->addSystemMessage(msgDate.toString(), QDateTime());
|
||||
}
|
||||
|
||||
// // Show each messages
|
||||
// ChatMessage* ca = genMessageActionAction(ToxID::fromString(it.sender), it.message, false, msgDateTime);
|
||||
// if (it.isSent)
|
||||
// {
|
||||
// ca->markAsSent();
|
||||
// } else {
|
||||
// if (processUndelivered)
|
||||
// {
|
||||
// int rec;
|
||||
// if (ca->isAction())
|
||||
// rec = Core::getInstance()->sendAction(f->getFriendID(), ca->getRawMessage());
|
||||
// else
|
||||
// rec = Core::getInstance()->sendMessage(f->getFriendID(), ca->getRawMessage());
|
||||
// registerReceipt(rec, it.id, ca);
|
||||
// }
|
||||
// }
|
||||
// historyMessages.append(ca);
|
||||
// }
|
||||
// std::swap(storedPrevId, previousId);
|
||||
// Show each messages
|
||||
ToxID id = ToxID::fromString(it.sender);
|
||||
ChatMessage* msg = chatWidget->addChatMessage(Core::getInstance()->getPeerName(id), it.message, id.isMine());
|
||||
if (it.isSent)
|
||||
{
|
||||
msg->markAsSent(msgDateTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (processUndelivered)
|
||||
{
|
||||
int rec = Core::getInstance()->sendMessage(f->getFriendID(), msg->toString());
|
||||
registerReceipt(rec, it.id, msg);
|
||||
}
|
||||
}
|
||||
historyMessages.append(msg);
|
||||
}
|
||||
std::swap(storedPrevId, previousId);
|
||||
|
||||
// int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();
|
||||
|
||||
|
@ -859,9 +850,9 @@ void ChatForm::deliverOfflineMsgs()
|
|||
{
|
||||
QString messageText = iter.value()->toString();
|
||||
int rec;
|
||||
//if (iter.value()->isAction())
|
||||
;//TODO: rec = Core::getInstance()->sendAction(f->getFriendID(), messageText);
|
||||
//else
|
||||
if (iter.value()->isAction())
|
||||
rec = Core::getInstance()->sendAction(f->getFriendID(), messageText);
|
||||
else
|
||||
rec = Core::getInstance()->sendMessage(f->getFriendID(), messageText);
|
||||
registerReceipt(rec, iter.key(), iter.value());
|
||||
}
|
||||
|
|
|
@ -79,7 +79,6 @@ private slots:
|
|||
void onAnswerCallTriggered();
|
||||
void onHangupCallTriggered();
|
||||
void onCancelCallTriggered();
|
||||
void onFileTansBtnClicked(QString widgetName, QString buttonName);
|
||||
void onFileSendFailed(int FriendId, const QString &fname);
|
||||
void onLoadHistory();
|
||||
void updateTime();
|
||||
|
|
|
@ -152,7 +152,12 @@ GenericChatForm::GenericChatForm(QWidget *parent) :
|
|||
|
||||
bool GenericChatForm::isEmpty()
|
||||
{
|
||||
//return chatWidget->isEmpty();
|
||||
return chatWidget->isEmpty();
|
||||
}
|
||||
|
||||
ChatLog *GenericChatForm::getChatLog() const
|
||||
{
|
||||
return chatWidget;
|
||||
}
|
||||
|
||||
void GenericChatForm::setName(const QString &newName)
|
||||
|
@ -193,35 +198,29 @@ void GenericChatForm::onSaveLogClicked()
|
|||
// file.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated The only reason it's still alive is because the groupchat API is a bit limited
|
||||
*/
|
||||
//void GenericChatForm::addMessage(const QString& author, const QString &message, bool isAction, const QDateTime &datetime)
|
||||
//{
|
||||
// MessageActionPtr ca = genMessageActionAction(author, message, isAction, datetime);
|
||||
// ca->markAsSent();
|
||||
// chatWidget->insertMessage(ca);
|
||||
//}
|
||||
|
||||
ChatMessage* GenericChatForm::addMessage(const ToxID& author, const QString &message, bool isAction,
|
||||
const QDateTime &datetime, bool isSent)
|
||||
{
|
||||
QString authorStr = previousId != author ? Core::getInstance()->getPeerName(author) : QString();
|
||||
previousId = author;
|
||||
QString authorStr = (author.isMine() ? Core::getInstance()->getUsername() : Core::getInstance()->getPeerName(author));
|
||||
|
||||
ChatMessage* msg = nullptr;
|
||||
if(isAction)
|
||||
msg = chatWidget->addChatAction(authorStr, message);
|
||||
else
|
||||
msg = chatWidget->addChatMessage(author != previousId ? authorStr : QString(), message, author.isMine());
|
||||
|
||||
ChatMessage* msg = chatWidget->addChatMessage(authorStr, message, datetime, false);
|
||||
if(isSent)
|
||||
msg->markAsSent(datetime);
|
||||
|
||||
if(!isAction)
|
||||
previousId = author;
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
||||
ChatMessage* GenericChatForm::addSelfMessage(const QString &message, bool isAction, const QDateTime &datetime, bool isSent)
|
||||
{
|
||||
QString authorStr = previousId != Core::getInstance()->getSelfId() ? Core::getInstance()->getUsername() : QString();
|
||||
previousId = Core::getInstance()->getSelfId();
|
||||
|
||||
return chatWidget->addChatMessage(authorStr, message, true);
|
||||
return addMessage(Core::getInstance()->getSelfId(), message, isAction, datetime, isSent);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -58,6 +58,8 @@ public:
|
|||
void addAlertMessage(const ToxID& author, QString message, QDateTime datetime);
|
||||
bool isEmpty();
|
||||
|
||||
ChatLog* getChatLog() const;
|
||||
|
||||
signals:
|
||||
void sendMessage(int, QString);
|
||||
void sendAction(int, QString);
|
||||
|
@ -75,10 +77,6 @@ protected slots:
|
|||
|
||||
protected:
|
||||
QString getElidedName(const QString& name);
|
||||
//TODO: MessageActionPtr genMessageActionAction(const QString& author, QString message, bool isAction, const QDateTime &datetime); ///< Deprecated
|
||||
// MessageActionPtr genMessageActionAction(const ToxID& author, QString message, bool isAction, const QDateTime &datetime);
|
||||
// MessageActionPtr genSelfActionAction(QString message, bool isAction, const QDateTime &datetime);
|
||||
// ChatMessage* genSystemInfoAction(const QString &message, const QString &type, const QDateTime &datetime);
|
||||
|
||||
ToxID previousId;
|
||||
QMenu menu;
|
||||
|
|
|
@ -902,6 +902,7 @@ void Widget::onGroupMessageReceived(int groupnumber, const QString& message, con
|
|||
if (targeted)
|
||||
;//TODO: g->chatForm->addAlertMessage(author, message, QDateTime::currentDateTime());
|
||||
else
|
||||
|
||||
;//TODO: g->chatForm->addMessage(author, message, isAction, QDateTime::currentDateTime());
|
||||
|
||||
if ((static_cast<GenericChatroomWidget*>(g->widget) != activeChatroomWidget) || isMinimized() || !isActiveWindow())
|
||||
|
@ -932,14 +933,14 @@ void Widget::onGroupNamelistChanged(int groupnumber, int peernumber, uint8_t Cha
|
|||
if (name.isEmpty())
|
||||
name = tr("<Unknown>", "Placeholder when we don't know someone's name in a group chat");
|
||||
g->addPeer(peernumber,name);
|
||||
//g->chatForm->addSystemInfoMessage(tr("%1 has joined the chat").arg(name), "green");
|
||||
g->chatForm->getChatLog()->addSystemMessage(tr("%1 has joined the chat").arg(name), QDateTime::currentDateTime());
|
||||
// we can't display these messages until irungentoo fixes peernumbers
|
||||
// https://github.com/irungentoo/toxcore/issues/1128
|
||||
}
|
||||
else if (change == TOX_CHAT_CHANGE_PEER_DEL)
|
||||
{
|
||||
g->removePeer(peernumber);
|
||||
//g->chatForm->addSystemInfoMessage(tr("%1 has left the chat").arg(name), "silver");
|
||||
g->chatForm->getChatLog()->addSystemMessage(tr("%1 has left the chat").arg(name), QDateTime::currentDateTime());
|
||||
}
|
||||
else if (change == TOX_CHAT_CHANGE_PEER_NAME) // core overwrites old name before telling us it changed...
|
||||
g->updatePeer(peernumber,core->getGroupPeerName(groupnumber, peernumber));
|
||||
|
@ -1086,7 +1087,7 @@ void Widget::onGroupSendResult(int groupId, const QString& message, int result)
|
|||
return;
|
||||
|
||||
if (result == -1)
|
||||
;//TODO: g->chatForm->addSystemInfoMessage(tr("Message failed to send"), "red", QDateTime::currentDateTime());
|
||||
g->chatForm->getChatLog()->addSystemMessage(tr("Message failed to send"), QDateTime::currentDateTime());
|
||||
}
|
||||
|
||||
void Widget::getPassword(QString info, int passtype, uint8_t* salt)
|
||||
|
@ -1158,6 +1159,6 @@ void Widget::clearAllReceipts()
|
|||
QList<Friend*> frnds = FriendList::getAllFriends();
|
||||
for (Friend *f : frnds)
|
||||
{
|
||||
//TODO: f->getChatForm()->clearReciepts();
|
||||
f->getChatForm()->clearReciepts();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user