mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Error messages in the case of message sending problems
This commit is contained in:
parent
255606c581
commit
1551614070
7
core.cpp
7
core.cpp
|
@ -479,7 +479,8 @@ void Core::sendMessage(int friendId, const QString& message)
|
|||
for (auto &cMsg :cMessages)
|
||||
{
|
||||
int messageId = tox_send_message(tox, friendId, cMsg.data(), cMsg.size());
|
||||
emit messageSentResult(friendId, message, messageId);
|
||||
if (messageId == 0)
|
||||
emit messageSentResult(friendId, message, messageId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -503,7 +504,9 @@ void Core::sendGroupMessage(int groupId, const QString& message)
|
|||
|
||||
for (auto &cMsg :cMessages)
|
||||
{
|
||||
tox_group_message_send(tox, groupId, cMsg.data(), cMsg.size());
|
||||
int ret = tox_group_message_send(tox, groupId, cMsg.data(), cMsg.size());
|
||||
if (ret == -1)
|
||||
emit groupSentResult(groupId, message, ret);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
1
core.h
1
core.h
|
@ -125,6 +125,7 @@ signals:
|
|||
void statusSet(Status status);
|
||||
|
||||
void messageSentResult(int friendId, const QString& message, int messageId);
|
||||
void groupSentResult(int groupId, const QString& message, int result);
|
||||
void actionSentResult(int friendId, const QString& action, int success);
|
||||
|
||||
void failedToAddFriend(const QString& userId);
|
||||
|
|
14
qtox.pro
14
qtox.pro
|
@ -107,13 +107,16 @@ HEADERS += widget/form/addfriendform.h \
|
|||
widget/friendlistwidget.h \
|
||||
widget/genericchatroomwidget.h \
|
||||
widget/form/genericchatform.h \
|
||||
widget/tool/chataction.h \
|
||||
widget/tool/chatactions/chataction.h \
|
||||
widget/chatareawidget.h \
|
||||
filetransferinstance.h \
|
||||
corestructs.h \
|
||||
coredefines.h \
|
||||
coreav.h \
|
||||
widget/settingsdialog.h
|
||||
widget/settingsdialog.h \
|
||||
widget/tool/chatactions/messageaction.h \
|
||||
widget/tool/chatactions/filetransferaction.h \
|
||||
widget/tool/chatactions/systemmessageaction.h
|
||||
|
||||
SOURCES += \
|
||||
widget/form/addfriendform.cpp \
|
||||
|
@ -146,8 +149,11 @@ SOURCES += \
|
|||
coreav.cpp \
|
||||
widget/genericchatroomwidget.cpp \
|
||||
widget/form/genericchatform.cpp \
|
||||
widget/tool/chataction.cpp \
|
||||
widget/tool/chatactions/chataction.cpp \
|
||||
widget/chatareawidget.cpp \
|
||||
filetransferinstance.cpp \
|
||||
corestructs.cpp \
|
||||
widget/settingsdialog.cpp
|
||||
widget/settingsdialog.cpp \
|
||||
widget/tool/chatactions/messageaction.cpp \
|
||||
widget/tool/chatactions/filetransferaction.cpp \
|
||||
widget/tool/chatactions/systemmessageaction.cpp
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
|
||||
#include "chatareawidget.h"
|
||||
#include "widget/tool/chataction.h"
|
||||
#include "widget/tool/chatactions/chataction.h"
|
||||
#include <QScrollBar>
|
||||
#include <QDesktopServices>
|
||||
#include <QTextTable>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#include "friend.h"
|
||||
#include "widget/friendwidget.h"
|
||||
#include "filetransferinstance.h"
|
||||
#include "widget/tool/chataction.h"
|
||||
#include "widget/tool/chatactions/filetransferaction.h"
|
||||
#include "widget/netcamview.h"
|
||||
#include "widget/chatareawidget.h"
|
||||
#include "widget/tool/chattextedit.h"
|
||||
|
|
|
@ -22,7 +22,8 @@
|
|||
#include "style.h"
|
||||
#include "widget/widget.h"
|
||||
#include "settings.h"
|
||||
#include "widget/tool/chataction.h"
|
||||
#include "widget/tool/chatactions/messageaction.h"
|
||||
#include "widget/tool/chatactions/systemmessageaction.h"
|
||||
#include "widget/chatareawidget.h"
|
||||
#include "widget/tool/chattextedit.h"
|
||||
|
||||
|
@ -208,3 +209,11 @@ void GenericChatForm::focusInput()
|
|||
{
|
||||
msgEdit->setFocus();
|
||||
}
|
||||
|
||||
void GenericChatForm::addSystemInfoMessage(const QString &message, const QString &type, const QDateTime &datetime)
|
||||
{
|
||||
previousName = "";
|
||||
QString date = datetime.toString(Settings::getInstance().getTimestampFormat());
|
||||
|
||||
chatWidget->insertMessage(new SystemMessageAction(message, type, date));
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ public:
|
|||
virtual void setName(const QString &newName);
|
||||
virtual void show(Ui::MainWindow &ui);
|
||||
void addMessage(QString author, QString message, QDateTime datetime=QDateTime::currentDateTime());
|
||||
void addSystemInfoMessage(const QString &message, const QString &type, const QDateTime &datetime=QDateTime::currentDateTime());
|
||||
|
||||
signals:
|
||||
void sendMessage(int, QString);
|
||||
|
|
|
@ -1,169 +0,0 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "chataction.h"
|
||||
#include "smileypack.h"
|
||||
#include <QStringList>
|
||||
#include <QBuffer>
|
||||
#include "filetransferinstance.h"
|
||||
|
||||
QString ChatAction::toHtmlChars(const QString &str)
|
||||
{
|
||||
static QList<QPair<QString, QString>> replaceList = {{"&","&"}, {">",">"}, {"<","<"}};
|
||||
QString res = str;
|
||||
|
||||
for (auto &it : replaceList)
|
||||
res = res.replace(it.first,it.second);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
QString ChatAction::QImage2base64(const QImage &img)
|
||||
{
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
img.save(&buffer, "PNG"); // writes image into ba in PNG format
|
||||
return ba.toBase64();
|
||||
}
|
||||
|
||||
QString ChatAction::getName()
|
||||
{
|
||||
if (isMe)
|
||||
return QString("<div class=name_me>" + toHtmlChars(name) + "</div>");
|
||||
else
|
||||
return QString("<div class=name>" + toHtmlChars(name) + "</div>");
|
||||
}
|
||||
|
||||
QString ChatAction::getDate()
|
||||
{
|
||||
QString res = date;
|
||||
return res;
|
||||
}
|
||||
|
||||
MessageAction::MessageAction(const QString &author, const QString &message, const QString &date, const bool &me) :
|
||||
ChatAction(me, author, date),
|
||||
message(message)
|
||||
{
|
||||
}
|
||||
|
||||
void MessageAction::setTextCursor(QTextCursor cursor)
|
||||
{
|
||||
// When this function is called, we're supposed to only update ourselve when needed
|
||||
// Nobody should ask us to do anything with our content, we're on our own
|
||||
// Except we never udpate on our own, so we can safely free our resources
|
||||
|
||||
(void) cursor;
|
||||
message.clear();
|
||||
message.squeeze();
|
||||
name.clear();
|
||||
name.squeeze();
|
||||
date.clear();
|
||||
date.squeeze();
|
||||
}
|
||||
|
||||
QString MessageAction::getMessage()
|
||||
{
|
||||
QString message_ = SmileyPack::getInstance().smileyfied(toHtmlChars(message));
|
||||
|
||||
// detect urls
|
||||
QRegExp exp("(www\\.|http[s]?:\\/\\/|ftp:\\/\\/)\\S+");
|
||||
int offset = 0;
|
||||
while ((offset = exp.indexIn(message_, offset)) != -1)
|
||||
{
|
||||
QString url = exp.cap();
|
||||
|
||||
// add scheme if not specified
|
||||
if (exp.cap(1) == "www.")
|
||||
url.prepend("http://");
|
||||
|
||||
QString htmledUrl = QString("<a href=\"%1\">%1</a>").arg(url);
|
||||
message_.replace(offset, exp.cap().length(), htmledUrl);
|
||||
|
||||
offset += htmledUrl.length();
|
||||
}
|
||||
|
||||
// detect text quotes
|
||||
QStringList messageLines = message_.split("\n");
|
||||
message_ = "";
|
||||
for (QString& s : messageLines)
|
||||
{
|
||||
if (QRegExp("^[ ]*>.*").exactMatch(s))
|
||||
message_ += "<span class=quote>>" + s.right(s.length()-4) + "</span><br/>";
|
||||
else
|
||||
message_ += s + "<br/>";
|
||||
}
|
||||
message_ = message_.left(message_.length()-4);
|
||||
|
||||
return QString("<div class=message>" + message_ + "</div>");
|
||||
}
|
||||
|
||||
FileTransferAction::FileTransferAction(FileTransferInstance *widget, const QString &author, const QString &date, const bool &me) :
|
||||
ChatAction(me, author, date)
|
||||
{
|
||||
w = widget;
|
||||
|
||||
connect(w, &FileTransferInstance::stateUpdated, this, &FileTransferAction::updateHtml);
|
||||
}
|
||||
|
||||
FileTransferAction::~FileTransferAction()
|
||||
{
|
||||
}
|
||||
|
||||
QString FileTransferAction::getMessage()
|
||||
{
|
||||
QString widgetHtml;
|
||||
if (w != nullptr)
|
||||
widgetHtml = w->getHtmlImage();
|
||||
else
|
||||
widgetHtml = "<div class=quote>EMPTY CONTENT</div>";
|
||||
return widgetHtml;
|
||||
}
|
||||
|
||||
void FileTransferAction::setTextCursor(QTextCursor cursor)
|
||||
{
|
||||
cur = cursor;
|
||||
cur.setKeepPositionOnInsert(true);
|
||||
int end=cur.selectionEnd();
|
||||
cur.setPosition(cur.position());
|
||||
cur.setPosition(end, QTextCursor::KeepAnchor);
|
||||
}
|
||||
|
||||
void FileTransferAction::updateHtml()
|
||||
{
|
||||
if (cur.isNull())
|
||||
return;
|
||||
|
||||
int pos = cur.selectionStart();
|
||||
cur.removeSelectedText();
|
||||
cur.setKeepPositionOnInsert(false);
|
||||
cur.insertHtml(getMessage());
|
||||
cur.setKeepPositionOnInsert(true);
|
||||
int end = cur.position();
|
||||
cur.setPosition(pos);
|
||||
cur.setPosition(end, QTextCursor::KeepAnchor);
|
||||
|
||||
// Free our ressources if we'll never need to update again
|
||||
if (w->getState() == FileTransferInstance::TransfState::tsCanceled
|
||||
|| w->getState() == FileTransferInstance::TransfState::tsFinished)
|
||||
{
|
||||
name.clear();
|
||||
name.squeeze();
|
||||
date.clear();
|
||||
date.squeeze();
|
||||
cur = QTextCursor();
|
||||
}
|
||||
}
|
53
widget/tool/chatactions/chataction.cpp
Normal file
53
widget/tool/chatactions/chataction.cpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "chataction.h"
|
||||
#include <QStringList>
|
||||
#include <QBuffer>
|
||||
|
||||
QString ChatAction::toHtmlChars(const QString &str)
|
||||
{
|
||||
static QList<QPair<QString, QString>> replaceList = {{"&","&"}, {">",">"}, {"<","<"}};
|
||||
QString res = str;
|
||||
|
||||
for (auto &it : replaceList)
|
||||
res = res.replace(it.first,it.second);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
QString ChatAction::QImage2base64(const QImage &img)
|
||||
{
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
buffer.open(QIODevice::WriteOnly);
|
||||
img.save(&buffer, "PNG"); // writes image into ba in PNG format
|
||||
return ba.toBase64();
|
||||
}
|
||||
|
||||
QString ChatAction::getName()
|
||||
{
|
||||
if (isMe)
|
||||
return QString("<div class=name_me>" + toHtmlChars(name) + "</div>");
|
||||
else
|
||||
return QString("<div class=name>" + toHtmlChars(name) + "</div>");
|
||||
}
|
||||
|
||||
QString ChatAction::getDate()
|
||||
{
|
||||
QString res = date;
|
||||
return res;
|
||||
}
|
|
@ -42,33 +42,4 @@ protected:
|
|||
QString name, date;
|
||||
};
|
||||
|
||||
class MessageAction : public ChatAction
|
||||
{
|
||||
public:
|
||||
MessageAction(const QString &author, const QString &message, const QString &date, const bool &me);
|
||||
virtual ~MessageAction(){;}
|
||||
virtual QString getMessage();
|
||||
virtual void setTextCursor(QTextCursor cursor) final;
|
||||
|
||||
private:
|
||||
QString message;
|
||||
};
|
||||
|
||||
class FileTransferAction : public ChatAction
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FileTransferAction(FileTransferInstance *widget, const QString &author, const QString &date, const bool &me);
|
||||
virtual ~FileTransferAction();
|
||||
virtual QString getMessage();
|
||||
virtual void setTextCursor(QTextCursor cursor) final;
|
||||
|
||||
private slots:
|
||||
void updateHtml();
|
||||
|
||||
private:
|
||||
FileTransferInstance *w;
|
||||
QTextCursor cur;
|
||||
};
|
||||
|
||||
#endif // CHATACTION_H
|
75
widget/tool/chatactions/filetransferaction.cpp
Normal file
75
widget/tool/chatactions/filetransferaction.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "filetransferaction.h"
|
||||
#include "filetransferinstance.h"
|
||||
|
||||
FileTransferAction::FileTransferAction(FileTransferInstance *widget, const QString &author, const QString &date, const bool &me) :
|
||||
ChatAction(me, author, date)
|
||||
{
|
||||
w = widget;
|
||||
|
||||
connect(w, &FileTransferInstance::stateUpdated, this, &FileTransferAction::updateHtml);
|
||||
}
|
||||
|
||||
FileTransferAction::~FileTransferAction()
|
||||
{
|
||||
}
|
||||
|
||||
QString FileTransferAction::getMessage()
|
||||
{
|
||||
QString widgetHtml;
|
||||
if (w != nullptr)
|
||||
widgetHtml = w->getHtmlImage();
|
||||
else
|
||||
widgetHtml = "<div class=quote>EMPTY CONTENT</div>";
|
||||
return widgetHtml;
|
||||
}
|
||||
|
||||
void FileTransferAction::setTextCursor(QTextCursor cursor)
|
||||
{
|
||||
cur = cursor;
|
||||
cur.setKeepPositionOnInsert(true);
|
||||
int end=cur.selectionEnd();
|
||||
cur.setPosition(cur.position());
|
||||
cur.setPosition(end, QTextCursor::KeepAnchor);
|
||||
}
|
||||
|
||||
void FileTransferAction::updateHtml()
|
||||
{
|
||||
if (cur.isNull())
|
||||
return;
|
||||
|
||||
int pos = cur.selectionStart();
|
||||
cur.removeSelectedText();
|
||||
cur.setKeepPositionOnInsert(false);
|
||||
cur.insertHtml(getMessage());
|
||||
cur.setKeepPositionOnInsert(true);
|
||||
int end = cur.position();
|
||||
cur.setPosition(pos);
|
||||
cur.setPosition(end, QTextCursor::KeepAnchor);
|
||||
|
||||
// Free our ressources if we'll never need to update again
|
||||
if (w->getState() == FileTransferInstance::TransfState::tsCanceled
|
||||
|| w->getState() == FileTransferInstance::TransfState::tsFinished)
|
||||
{
|
||||
name.clear();
|
||||
name.squeeze();
|
||||
date.clear();
|
||||
date.squeeze();
|
||||
cur = QTextCursor();
|
||||
}
|
||||
}
|
39
widget/tool/chatactions/filetransferaction.h
Normal file
39
widget/tool/chatactions/filetransferaction.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef FILETRANSFERACTION_H
|
||||
#define FILETRANSFERACTION_H
|
||||
|
||||
#include "widget/tool/chatactions/chataction.h"
|
||||
|
||||
class FileTransferAction : public ChatAction
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FileTransferAction(FileTransferInstance *widget, const QString &author, const QString &date, const bool &me);
|
||||
virtual ~FileTransferAction();
|
||||
virtual QString getMessage();
|
||||
virtual void setTextCursor(QTextCursor cursor) final;
|
||||
|
||||
private slots:
|
||||
void updateHtml();
|
||||
|
||||
private:
|
||||
FileTransferInstance *w;
|
||||
QTextCursor cur;
|
||||
};
|
||||
|
||||
#endif // FILETRANSFERACTION_H
|
75
widget/tool/chatactions/messageaction.cpp
Normal file
75
widget/tool/chatactions/messageaction.cpp
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "messageaction.h"
|
||||
#include "smileypack.h"
|
||||
|
||||
MessageAction::MessageAction(const QString &author, const QString &message, const QString &date, const bool &me) :
|
||||
ChatAction(me, author, date),
|
||||
message(message)
|
||||
{
|
||||
}
|
||||
|
||||
void MessageAction::setTextCursor(QTextCursor cursor)
|
||||
{
|
||||
// When this function is called, we're supposed to only update ourselve when needed
|
||||
// Nobody should ask us to do anything with our content, we're on our own
|
||||
// Except we never udpate on our own, so we can safely free our resources
|
||||
|
||||
(void) cursor;
|
||||
message.clear();
|
||||
message.squeeze();
|
||||
name.clear();
|
||||
name.squeeze();
|
||||
date.clear();
|
||||
date.squeeze();
|
||||
}
|
||||
|
||||
QString MessageAction::getMessage()
|
||||
{
|
||||
QString message_ = SmileyPack::getInstance().smileyfied(toHtmlChars(message));
|
||||
|
||||
// detect urls
|
||||
QRegExp exp("(www\\.|http[s]?:\\/\\/|ftp:\\/\\/)\\S+");
|
||||
int offset = 0;
|
||||
while ((offset = exp.indexIn(message_, offset)) != -1)
|
||||
{
|
||||
QString url = exp.cap();
|
||||
|
||||
// add scheme if not specified
|
||||
if (exp.cap(1) == "www.")
|
||||
url.prepend("http://");
|
||||
|
||||
QString htmledUrl = QString("<a href=\"%1\">%1</a>").arg(url);
|
||||
message_.replace(offset, exp.cap().length(), htmledUrl);
|
||||
|
||||
offset += htmledUrl.length();
|
||||
}
|
||||
|
||||
// detect text quotes
|
||||
QStringList messageLines = message_.split("\n");
|
||||
message_ = "";
|
||||
for (QString& s : messageLines)
|
||||
{
|
||||
if (QRegExp("^[ ]*>.*").exactMatch(s))
|
||||
message_ += "<span class=quote>>" + s.right(s.length()-4) + "</span><br/>";
|
||||
else
|
||||
message_ += s + "<br/>";
|
||||
}
|
||||
message_ = message_.left(message_.length()-4);
|
||||
|
||||
return QString("<div class=message>" + message_ + "</div>");
|
||||
}
|
34
widget/tool/chatactions/messageaction.h
Normal file
34
widget/tool/chatactions/messageaction.h
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef MESSAGEACTION_H
|
||||
#define MESSAGEACTION_H
|
||||
|
||||
#include "widget/tool/chatactions/chataction.h"
|
||||
|
||||
class MessageAction : public ChatAction
|
||||
{
|
||||
public:
|
||||
MessageAction(const QString &author, const QString &message, const QString &date, const bool &me);
|
||||
virtual ~MessageAction(){;}
|
||||
virtual QString getMessage();
|
||||
virtual void setTextCursor(QTextCursor cursor) final;
|
||||
|
||||
private:
|
||||
QString message;
|
||||
};
|
||||
|
||||
#endif // MESSAGEACTION_H
|
46
widget/tool/chatactions/systemmessageaction.cpp
Normal file
46
widget/tool/chatactions/systemmessageaction.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "systemmessageaction.h"
|
||||
|
||||
SystemMessageAction::SystemMessageAction(const QString &message, const QString &type, const QString &date) :
|
||||
ChatAction(false, QString(), date),
|
||||
message(message),
|
||||
type(type)
|
||||
{
|
||||
}
|
||||
|
||||
QString SystemMessageAction::getMessage()
|
||||
{
|
||||
return QString("<table width=100%><tr><td align=center><div class=" + type + ">" + message + "</td><tr></div></table>");
|
||||
}
|
||||
|
||||
void SystemMessageAction::setTextCursor(QTextCursor cursor)
|
||||
{
|
||||
// When this function is called, we're supposed to only update ourselve when needed
|
||||
// Nobody should ask us to do anything with our content, we're on our own
|
||||
// Except we never udpate on our own, so we can safely free our resources
|
||||
|
||||
(void) cursor;
|
||||
message.clear();
|
||||
message.squeeze();
|
||||
name.clear();
|
||||
name.squeeze();
|
||||
date.clear();
|
||||
date.squeeze();
|
||||
type.clear();
|
||||
type.squeeze();
|
||||
}
|
37
widget/tool/chatactions/systemmessageaction.h
Normal file
37
widget/tool/chatactions/systemmessageaction.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
Copyright (C) 2014 by Project Tox <https://tox.im>
|
||||
|
||||
This file is part of qTox, a Qt-based graphical interface for Tox.
|
||||
|
||||
This program is libre software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#ifndef SYSTEMMESSAGEACTION_H
|
||||
#define SYSTEMMESSAGEACTION_H
|
||||
|
||||
#include "widget/tool/chatactions/chataction.h"
|
||||
|
||||
class SystemMessageAction : public ChatAction
|
||||
{
|
||||
public:
|
||||
SystemMessageAction(const QString &message, const QString& type, const QString &date);
|
||||
virtual ~SystemMessageAction(){;}
|
||||
virtual void setTextCursor(QTextCursor cursor) final;
|
||||
|
||||
virtual QString getName() {return QString();}
|
||||
virtual QString getMessage();
|
||||
|
||||
private:
|
||||
QString message;
|
||||
QString type;
|
||||
};
|
||||
|
||||
#endif // SYSTEMMESSAGEACTION_H
|
|
@ -197,6 +197,9 @@ Widget::Widget(QWidget *parent)
|
|||
connect(core, &Core::groupNamelistChanged, this, &Widget::onGroupNamelistChanged);
|
||||
connect(core, &Core::emptyGroupCreated, this, &Widget::onEmptyGroupCreated);
|
||||
|
||||
connect(core, SIGNAL(messageSentResult(int,QString,int)), this, SLOT(onMessageSendResult(int,QString,int)));
|
||||
connect(core, SIGNAL(groupSentResult(int,QString,int)), this, SLOT(onGroupSendResult(int,QString,int)));
|
||||
|
||||
connect(this, &Widget::statusSet, core, &Core::setStatus);
|
||||
connect(this, &Widget::friendRequested, core, &Core::requestFriendship);
|
||||
connect(this, &Widget::friendRequestAccepted, core, &Core::acceptFriendRequest);
|
||||
|
@ -1060,3 +1063,25 @@ bool Widget::getIsWindowMinimized()
|
|||
{
|
||||
return static_cast<bool>(isWindowMinimized);
|
||||
}
|
||||
|
||||
void Widget::onMessageSendResult(int friendId, const QString& message, int messageId)
|
||||
{
|
||||
Q_UNUSED(message)
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
if (!f)
|
||||
return;
|
||||
|
||||
if (!messageId)
|
||||
f->chatForm->addSystemInfoMessage("Message failed to send", "red");
|
||||
}
|
||||
|
||||
void Widget::onGroupSendResult(int groupId, const QString& message, int result)
|
||||
{
|
||||
Q_UNUSED(message)
|
||||
Group* g = GroupList::findGroup(groupId);
|
||||
if (!g)
|
||||
return;
|
||||
|
||||
if (result == -1)
|
||||
g->chatForm->addSystemInfoMessage("Message failed to send", "red");
|
||||
}
|
||||
|
|
|
@ -104,6 +104,8 @@ private slots:
|
|||
void setStatusOnline();
|
||||
void setStatusAway();
|
||||
void setStatusBusy();
|
||||
void onMessageSendResult(int friendId, const QString& message, int messageId);
|
||||
void onGroupSendResult(int groupId, const QString& message, int result);
|
||||
|
||||
protected slots:
|
||||
void moveWindow(QMouseEvent *e);
|
||||
|
|
Loading…
Reference in New Issue
Block a user