1
0
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:
krepa098 2014-12-13 21:11:03 +01:00
parent 380d7b9a07
commit 3190530686
14 changed files with 139 additions and 94 deletions

View File

@ -61,6 +61,14 @@ int ChatLine::getRowIndex() const
return rowIndex; return rowIndex;
} }
ChatLineContent *ChatLine::getContent(int col) const
{
if(col < content.size() && col >= 0)
return content[col];
return nullptr;
}
void ChatLine::selectionCleared() void ChatLine::selectionCleared()
{ {
for(ChatLineContent* c : content) for(ChatLineContent* c : content)

View File

@ -72,6 +72,7 @@ public:
int getColumnCount(); int getColumnCount();
int getRowIndex() const; int getRowIndex() const;
ChatLineContent* getContent(int col) const;
bool isOverSelection(QPointF scenePos); bool isOverSelection(QPointF scenePos);

View File

@ -96,6 +96,26 @@ ChatMessage* ChatLog::addChatMessage(const QString& sender, const QString& msg,
return line; return line;
} }
ChatMessage *ChatLog::addChatAction(const QString &sender, const QString &msg, const QDateTime &timestamp)
{
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 *ChatLog::addSystemMessage(const QString &msg, const QDateTime& timestamp)
{ {
ChatMessage* line = new ChatMessage(scene, msg); ChatMessage* line = new ChatMessage(scene, msg);
@ -435,6 +455,11 @@ QString ChatLog::getSelectedText() const
return QString(); return QString();
} }
bool ChatLog::isEmpty() const
{
return lines.isEmpty();
}
void ChatLog::showContextMenu(const QPoint& globalPos, const QPointF& scenePos) void ChatLog::showContextMenu(const QPoint& globalPos, const QPointF& scenePos)
{ {
QMenu menu; QMenu menu;

View File

@ -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, const QDateTime& timestamp, bool self);
ChatMessage* addChatMessage(const QString& sender, const QString& msg, 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* addSystemMessage(const QString& msg, const QDateTime& timestamp);
ChatMessage* addFileTransferMessage(const QString& sender, const ToxFile& file, const QDateTime &timestamp, bool self); ChatMessage* addFileTransferMessage(const QString& sender, const ToxFile& file, const QDateTime &timestamp, bool self);
@ -48,6 +50,8 @@ public:
void copySelectedText() const; void copySelectedText() const;
QString getSelectedText() const; QString getSelectedText() const;
bool isEmpty() const;
protected: protected:
QRect getVisibleRect() const; QRect getVisibleRect() const;
ChatLineContent* getContentFromPos(QPointF scenePos) const; ChatLineContent* getContentFromPos(QPointF scenePos) const;

View File

@ -37,3 +37,13 @@ QString ChatMessage::toString() const
{ {
return rawString; return rawString;
} }
bool ChatMessage::isAction() const
{
return action;
}
void ChatMessage::setAsAction()
{
action = true;
}

View File

@ -28,10 +28,13 @@ public:
void markAsSent(const QDateTime& time); void markAsSent(const QDateTime& time);
QString toString() const; QString toString() const;
bool isAction() const;
void setAsAction();
private: private:
ChatLineContent* midColumn = nullptr; ChatLineContent* midColumn = nullptr;
QString rawString; QString rawString;
bool action = false;
}; };
#endif // CHATMESSAGE_H #endif // CHATMESSAGE_H

View File

@ -69,6 +69,21 @@ FileTransferWidget::~FileTransferWidget()
delete ui; 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) void FileTransferWidget::onFileTransferInfo(ToxFile file)
{ {
if(fileInfo != file) if(fileInfo != file)
@ -255,18 +270,7 @@ void FileTransferWidget::handleButton(QPushButton *btn)
if(btn->objectName() == "accept") if(btn->objectName() == "accept")
{ {
QString path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(fileInfo.fileName)); QString path = QFileDialog::getSaveFileName(0, tr("Save a file","Title of the file saving dialog"), QDir::home().filePath(fileInfo.fileName));
acceptTransfer(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);
} }
} }

View File

@ -36,6 +36,8 @@ public:
explicit FileTransferWidget(QWidget *parent, ToxFile file); explicit FileTransferWidget(QWidget *parent, ToxFile file);
virtual ~FileTransferWidget(); virtual ~FileTransferWidget();
void acceptTransfer(const QString& path);
protected slots: protected slots:
void onFileTransferInfo(ToxFile file); void onFileTransferInfo(ToxFile file);
void onFileTransferAccepted(ToxFile file); void onFileTransferAccepted(ToxFile file);

View File

@ -1054,7 +1054,7 @@ void Core::setAvatar(uint8_t format, const QByteArray& data)
ToxID Core::getSelfId() const ToxID Core::getSelfId() const
{ {
uint8_t friendAddress[TOX_FRIEND_ADDRESS_SIZE]; uint8_t friendAddress[TOX_FRIEND_ADDRESS_SIZE] = {0};
tox_get_address(tox, friendAddress); tox_get_address(tox, friendAddress);
return ToxID::fromString(CFriendAddress::toString(friendAddress)); return ToxID::fromString(CFriendAddress::toString(friendAddress));
} }

View File

@ -39,6 +39,7 @@
#include "src/misc/settings.h" #include "src/misc/settings.h"
#include "src/misc/cstring.h" #include "src/misc/cstring.h"
#include "src/chatlog/chatmessage.h" #include "src/chatlog/chatmessage.h"
#include "src/chatlog/content/filetransferwidget.h"
ChatForm::ChatForm(Friend* chatFriend) ChatForm::ChatForm(Friend* chatFriend)
: f(chatFriend) : f(chatFriend)
@ -74,7 +75,6 @@ ChatForm::ChatForm(Friend* chatFriend)
connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered); connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered);
connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle())); connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle()));
connect(volButton, SIGNAL(clicked()), this, SLOT(onVolMuteToggle())); connect(volButton, SIGNAL(clicked()), this, SLOT(onVolMuteToggle()));
//TODO: connect(chatWidget, &ChatAreaWidget::onFileTranfertInterract, this, &ChatForm::onFileTansBtnClicked);
connect(Core::getInstance(), &Core::fileSendFailed, this, &ChatForm::onFileSendFailed); connect(Core::getInstance(), &Core::fileSendFailed, this, &ChatForm::onFileSendFailed);
connect(this, SIGNAL(chatAreaCleared()), this, SLOT(clearReciepts())); connect(this, SIGNAL(chatAreaCleared()), this, SLOT(clearReciepts()));
@ -197,11 +197,14 @@ void ChatForm::onFileRecvRequest(ToxFile file)
previousId = friendId; previousId = friendId;
} }
chatWidget->addFileTransferMessage(name, file, QDateTime::currentDateTime(), false); ChatMessage* msg = chatWidget->addFileTransferMessage(name, file, QDateTime::currentDateTime(), false);
//TODO: if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty()
// if (!Settings::getInstance().getAutoAcceptDir(Core::getInstance()->getFriendAddress(f->getFriendID())).isEmpty() || Settings::getInstance().getAutoSaveEnabled())
// || Settings::getInstance().getAutoSaveEnabled()) {
// fileTrans->pressFromHtml("btnB"); 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) 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())); 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(); Widget* w = Widget::getInstance();
if (!w->isFriendWidgetCurActiveWidget(f)|| w->isMinimized() || !w->isActiveWindow()) 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(callButton, SIGNAL(clicked()), this, SLOT(onCallTriggered()));
connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered())); connect(videoButton, SIGNAL(clicked()), this, SLOT(onVideoCallTriggered()));
//TODO: addSystemInfoMessage(tr("Call rejected"), "white", QDateTime::currentDateTime()); chatWidget->addSystemMessage(tr("Call rejected"), QDateTime::currentDateTime());
netcam->hide(); 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) void ChatForm::onFileSendFailed(int FriendId, const QString &fname)
{ {
if (FriendId != f->getFriendID()) if (FriendId != f->getFriendID())
@ -708,39 +699,39 @@ void ChatForm::loadHistory(QDateTime since, bool processUndelivered)
ToxID storedPrevId; ToxID storedPrevId;
std::swap(storedPrevId, previousId); std::swap(storedPrevId, previousId);
// QList<ChatMessage*> historyMessages; QList<ChatMessage*> historyMessages;
// QDate lastDate(1,0,0); //TODO: possibly broken
// for (const auto &it : msgs) QDate lastDate(1,0,0);
// { for (const auto &it : msgs)
// // Show the date every new day {
// QDateTime msgDateTime = it.timestamp.toLocalTime(); // Show the date every new day
// QDate msgDate = msgDateTime.date(); QDateTime msgDateTime = it.timestamp.toLocalTime();
// if (msgDate > lastDate) QDate msgDate = msgDateTime.date();
// { if (msgDate > lastDate)
// lastDate = msgDate; {
// //TODO: historyMessages.append(genSystemInfoAction(msgDate.toString(),"",QDateTime())); lastDate = msgDate;
// } chatWidget->addSystemMessage(msgDate.toString(), QDateTime());
}
// // Show each messages // Show each messages
// ChatMessage* ca = genMessageActionAction(ToxID::fromString(it.sender), it.message, false, msgDateTime); ToxID id = ToxID::fromString(it.sender);
// if (it.isSent) ChatMessage* msg = chatWidget->addChatMessage(Core::getInstance()->getPeerName(id), it.message, id.isMine());
// { if (it.isSent)
// ca->markAsSent(); {
// } else { msg->markAsSent(msgDateTime);
// if (processUndelivered) }
// { else
// int rec; {
// if (ca->isAction()) if (processUndelivered)
// rec = Core::getInstance()->sendAction(f->getFriendID(), ca->getRawMessage()); {
// else int rec = Core::getInstance()->sendMessage(f->getFriendID(), msg->toString());
// rec = Core::getInstance()->sendMessage(f->getFriendID(), ca->getRawMessage()); registerReceipt(rec, it.id, msg);
// registerReceipt(rec, it.id, ca); }
// } }
// } historyMessages.append(msg);
// historyMessages.append(ca); }
// } std::swap(storedPrevId, previousId);
// std::swap(storedPrevId, previousId);
// int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value(); // int savedSliderPos = chatWidget->verticalScrollBar()->maximum() - chatWidget->verticalScrollBar()->value();
@ -859,9 +850,9 @@ void ChatForm::deliverOfflineMsgs()
{ {
QString messageText = iter.value()->toString(); QString messageText = iter.value()->toString();
int rec; int rec;
//if (iter.value()->isAction()) if (iter.value()->isAction())
;//TODO: rec = Core::getInstance()->sendAction(f->getFriendID(), messageText); rec = Core::getInstance()->sendAction(f->getFriendID(), messageText);
//else else
rec = Core::getInstance()->sendMessage(f->getFriendID(), messageText); rec = Core::getInstance()->sendMessage(f->getFriendID(), messageText);
registerReceipt(rec, iter.key(), iter.value()); registerReceipt(rec, iter.key(), iter.value());
} }

View File

@ -79,7 +79,6 @@ private slots:
void onAnswerCallTriggered(); void onAnswerCallTriggered();
void onHangupCallTriggered(); void onHangupCallTriggered();
void onCancelCallTriggered(); void onCancelCallTriggered();
void onFileTansBtnClicked(QString widgetName, QString buttonName);
void onFileSendFailed(int FriendId, const QString &fname); void onFileSendFailed(int FriendId, const QString &fname);
void onLoadHistory(); void onLoadHistory();
void updateTime(); void updateTime();

View File

@ -152,7 +152,12 @@ GenericChatForm::GenericChatForm(QWidget *parent) :
bool GenericChatForm::isEmpty() bool GenericChatForm::isEmpty()
{ {
//return chatWidget->isEmpty(); return chatWidget->isEmpty();
}
ChatLog *GenericChatForm::getChatLog() const
{
return chatWidget;
} }
void GenericChatForm::setName(const QString &newName) void GenericChatForm::setName(const QString &newName)
@ -193,35 +198,29 @@ void GenericChatForm::onSaveLogClicked()
// file.close(); // 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, ChatMessage* GenericChatForm::addMessage(const ToxID& author, const QString &message, bool isAction,
const QDateTime &datetime, bool isSent) const QDateTime &datetime, bool isSent)
{ {
QString authorStr = previousId != author ? Core::getInstance()->getPeerName(author) : QString(); QString authorStr = (author.isMine() ? Core::getInstance()->getUsername() : Core::getInstance()->getPeerName(author));
previousId = 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) if(isSent)
msg->markAsSent(datetime); msg->markAsSent(datetime);
if(!isAction)
previousId = author;
return msg; return msg;
} }
ChatMessage* GenericChatForm::addSelfMessage(const QString &message, bool isAction, const QDateTime &datetime, bool isSent) ChatMessage* GenericChatForm::addSelfMessage(const QString &message, bool isAction, const QDateTime &datetime, bool isSent)
{ {
QString authorStr = previousId != Core::getInstance()->getSelfId() ? Core::getInstance()->getUsername() : QString(); return addMessage(Core::getInstance()->getSelfId(), message, isAction, datetime, isSent);
previousId = Core::getInstance()->getSelfId();
return chatWidget->addChatMessage(authorStr, message, true);
} }
/** /**

View File

@ -58,6 +58,8 @@ public:
void addAlertMessage(const ToxID& author, QString message, QDateTime datetime); void addAlertMessage(const ToxID& author, QString message, QDateTime datetime);
bool isEmpty(); bool isEmpty();
ChatLog* getChatLog() const;
signals: signals:
void sendMessage(int, QString); void sendMessage(int, QString);
void sendAction(int, QString); void sendAction(int, QString);
@ -75,10 +77,6 @@ protected slots:
protected: protected:
QString getElidedName(const QString& name); 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; ToxID previousId;
QMenu menu; QMenu menu;

View File

@ -902,6 +902,7 @@ void Widget::onGroupMessageReceived(int groupnumber, const QString& message, con
if (targeted) if (targeted)
;//TODO: g->chatForm->addAlertMessage(author, message, QDateTime::currentDateTime()); ;//TODO: g->chatForm->addAlertMessage(author, message, QDateTime::currentDateTime());
else else
;//TODO: g->chatForm->addMessage(author, message, isAction, QDateTime::currentDateTime()); ;//TODO: g->chatForm->addMessage(author, message, isAction, QDateTime::currentDateTime());
if ((static_cast<GenericChatroomWidget*>(g->widget) != activeChatroomWidget) || isMinimized() || !isActiveWindow()) 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()) if (name.isEmpty())
name = tr("<Unknown>", "Placeholder when we don't know someone's name in a group chat"); name = tr("<Unknown>", "Placeholder when we don't know someone's name in a group chat");
g->addPeer(peernumber,name); 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 // we can't display these messages until irungentoo fixes peernumbers
// https://github.com/irungentoo/toxcore/issues/1128 // https://github.com/irungentoo/toxcore/issues/1128
} }
else if (change == TOX_CHAT_CHANGE_PEER_DEL) else if (change == TOX_CHAT_CHANGE_PEER_DEL)
{ {
g->removePeer(peernumber); 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... else if (change == TOX_CHAT_CHANGE_PEER_NAME) // core overwrites old name before telling us it changed...
g->updatePeer(peernumber,core->getGroupPeerName(groupnumber, peernumber)); g->updatePeer(peernumber,core->getGroupPeerName(groupnumber, peernumber));
@ -1086,7 +1087,7 @@ void Widget::onGroupSendResult(int groupId, const QString& message, int result)
return; return;
if (result == -1) 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) void Widget::getPassword(QString info, int passtype, uint8_t* salt)
@ -1158,6 +1159,6 @@ void Widget::clearAllReceipts()
QList<Friend*> frnds = FriendList::getAllFriends(); QList<Friend*> frnds = FriendList::getAllFriends();
for (Friend *f : frnds) for (Friend *f : frnds)
{ {
//TODO: f->getChatForm()->clearReciepts(); f->getChatForm()->clearReciepts();
} }
} }