From 15516140704469c09ec5e6f17671ec99f8b7eef4 Mon Sep 17 00:00:00 2001 From: apprb Date: Tue, 23 Sep 2014 23:35:06 +0700 Subject: [PATCH 1/2] Error messages in the case of message sending problems --- core.cpp | 7 +- core.h | 1 + qtox.pro | 14 +- widget/chatareawidget.cpp | 2 +- widget/form/chatform.cpp | 2 +- widget/form/genericchatform.cpp | 11 +- widget/form/genericchatform.h | 1 + widget/tool/chataction.cpp | 169 ------------------ widget/tool/chatactions/chataction.cpp | 53 ++++++ widget/tool/{ => chatactions}/chataction.h | 29 --- .../tool/chatactions/filetransferaction.cpp | 75 ++++++++ widget/tool/chatactions/filetransferaction.h | 39 ++++ widget/tool/chatactions/messageaction.cpp | 75 ++++++++ widget/tool/chatactions/messageaction.h | 34 ++++ .../tool/chatactions/systemmessageaction.cpp | 46 +++++ widget/tool/chatactions/systemmessageaction.h | 37 ++++ widget/widget.cpp | 25 +++ widget/widget.h | 2 + 18 files changed, 415 insertions(+), 207 deletions(-) delete mode 100644 widget/tool/chataction.cpp create mode 100644 widget/tool/chatactions/chataction.cpp rename widget/tool/{ => chatactions}/chataction.h (64%) create mode 100644 widget/tool/chatactions/filetransferaction.cpp create mode 100644 widget/tool/chatactions/filetransferaction.h create mode 100644 widget/tool/chatactions/messageaction.cpp create mode 100644 widget/tool/chatactions/messageaction.h create mode 100644 widget/tool/chatactions/systemmessageaction.cpp create mode 100644 widget/tool/chatactions/systemmessageaction.h diff --git a/core.cpp b/core.cpp index c37c78146..e44988d56 100644 --- a/core.cpp +++ b/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); } } diff --git a/core.h b/core.h index 706f448a3..ed1606331 100644 --- a/core.h +++ b/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); diff --git a/qtox.pro b/qtox.pro index d22a406da..68845488e 100644 --- a/qtox.pro +++ b/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 diff --git a/widget/chatareawidget.cpp b/widget/chatareawidget.cpp index f52262e5d..524039d20 100644 --- a/widget/chatareawidget.cpp +++ b/widget/chatareawidget.cpp @@ -15,7 +15,7 @@ */ #include "chatareawidget.h" -#include "widget/tool/chataction.h" +#include "widget/tool/chatactions/chataction.h" #include #include #include diff --git a/widget/form/chatform.cpp b/widget/form/chatform.cpp index 0114a92db..33e32879a 100644 --- a/widget/form/chatform.cpp +++ b/widget/form/chatform.cpp @@ -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" diff --git a/widget/form/genericchatform.cpp b/widget/form/genericchatform.cpp index f5681f1c6..0e765b397 100644 --- a/widget/form/genericchatform.cpp +++ b/widget/form/genericchatform.cpp @@ -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)); +} diff --git a/widget/form/genericchatform.h b/widget/form/genericchatform.h index 95940cda5..72dc94fd9 100644 --- a/widget/form/genericchatform.h +++ b/widget/form/genericchatform.h @@ -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); diff --git a/widget/tool/chataction.cpp b/widget/tool/chataction.cpp deleted file mode 100644 index bcd1f1080..000000000 --- a/widget/tool/chataction.cpp +++ /dev/null @@ -1,169 +0,0 @@ -/* - Copyright (C) 2014 by Project Tox - - 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 -#include -#include "filetransferinstance.h" - -QString ChatAction::toHtmlChars(const QString &str) -{ - static QList> 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("
" + toHtmlChars(name) + "
"); - else - return QString("
" + toHtmlChars(name) + "
"); -} - -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("%1").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_ += ">" + s.right(s.length()-4) + "
"; - else - message_ += s + "
"; - } - message_ = message_.left(message_.length()-4); - - return QString("
" + message_ + "
"); -} - -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 = "
EMPTY CONTENT
"; - 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(); - } -} diff --git a/widget/tool/chatactions/chataction.cpp b/widget/tool/chatactions/chataction.cpp new file mode 100644 index 000000000..7758aae33 --- /dev/null +++ b/widget/tool/chatactions/chataction.cpp @@ -0,0 +1,53 @@ +/* + Copyright (C) 2014 by Project Tox + + 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 +#include + +QString ChatAction::toHtmlChars(const QString &str) +{ + static QList> 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("
" + toHtmlChars(name) + "
"); + else + return QString("
" + toHtmlChars(name) + "
"); +} + +QString ChatAction::getDate() +{ + QString res = date; + return res; +} diff --git a/widget/tool/chataction.h b/widget/tool/chatactions/chataction.h similarity index 64% rename from widget/tool/chataction.h rename to widget/tool/chatactions/chataction.h index a324a41c6..16c9f179b 100644 --- a/widget/tool/chataction.h +++ b/widget/tool/chatactions/chataction.h @@ -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 diff --git a/widget/tool/chatactions/filetransferaction.cpp b/widget/tool/chatactions/filetransferaction.cpp new file mode 100644 index 000000000..12e2a1ac6 --- /dev/null +++ b/widget/tool/chatactions/filetransferaction.cpp @@ -0,0 +1,75 @@ +/* + Copyright (C) 2014 by Project Tox + + 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 = "
EMPTY CONTENT
"; + 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(); + } +} diff --git a/widget/tool/chatactions/filetransferaction.h b/widget/tool/chatactions/filetransferaction.h new file mode 100644 index 000000000..ee6d0e11c --- /dev/null +++ b/widget/tool/chatactions/filetransferaction.h @@ -0,0 +1,39 @@ +/* + Copyright (C) 2014 by Project Tox + + 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 diff --git a/widget/tool/chatactions/messageaction.cpp b/widget/tool/chatactions/messageaction.cpp new file mode 100644 index 000000000..fa396468c --- /dev/null +++ b/widget/tool/chatactions/messageaction.cpp @@ -0,0 +1,75 @@ +/* + Copyright (C) 2014 by Project Tox + + 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("%1").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_ += ">" + s.right(s.length()-4) + "
"; + else + message_ += s + "
"; + } + message_ = message_.left(message_.length()-4); + + return QString("
" + message_ + "
"); +} diff --git a/widget/tool/chatactions/messageaction.h b/widget/tool/chatactions/messageaction.h new file mode 100644 index 000000000..baa68898a --- /dev/null +++ b/widget/tool/chatactions/messageaction.h @@ -0,0 +1,34 @@ +/* + Copyright (C) 2014 by Project Tox + + 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 diff --git a/widget/tool/chatactions/systemmessageaction.cpp b/widget/tool/chatactions/systemmessageaction.cpp new file mode 100644 index 000000000..32457c6ed --- /dev/null +++ b/widget/tool/chatactions/systemmessageaction.cpp @@ -0,0 +1,46 @@ +/* + Copyright (C) 2014 by Project Tox + + 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("
" + message + "
"); +} + +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(); +} diff --git a/widget/tool/chatactions/systemmessageaction.h b/widget/tool/chatactions/systemmessageaction.h new file mode 100644 index 000000000..b628f7e04 --- /dev/null +++ b/widget/tool/chatactions/systemmessageaction.h @@ -0,0 +1,37 @@ +/* + Copyright (C) 2014 by Project Tox + + 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 diff --git a/widget/widget.cpp b/widget/widget.cpp index 36b2c33c1..64b09de80 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -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(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"); +} diff --git a/widget/widget.h b/widget/widget.h index 035ea2ae0..e85701a55 100644 --- a/widget/widget.h +++ b/widget/widget.h @@ -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); From 06178f00d99398213094b70290a626a5b8aa4f28 Mon Sep 17 00:00:00 2001 From: apprb Date: Tue, 23 Sep 2014 23:52:06 +0700 Subject: [PATCH 2/2] File send error message --- core.cpp | 1 + core.h | 2 ++ widget/form/chatform.cpp | 9 +++++++++ widget/form/chatform.h | 1 + 4 files changed, 13 insertions(+) diff --git a/core.cpp b/core.cpp index e44988d56..a9b0843c3 100644 --- a/core.cpp +++ b/core.cpp @@ -517,6 +517,7 @@ void Core::sendFile(int32_t friendId, QString Filename, QString FilePath, long l if (fileNum == -1) { qWarning() << "Core::sendFile: Can't create the Tox file sender"; + emit fileSendFailed(friendId, Filename); return; } qDebug() << QString("Core::sendFile: Created file sender %1 with friend %2").arg(fileNum).arg(friendId); diff --git a/core.h b/core.h index ed1606331..0ae48f688 100644 --- a/core.h +++ b/core.h @@ -150,6 +150,8 @@ signals: void fileTransferInfo(int FriendId, int FileNum, int64_t Filesize, int64_t BytesSent, ToxFile::FileDirection direction); void fileTransferRemotePausedUnpaused(ToxFile file, bool paused); + void fileSendFailed(int FriendId, const QString& fname); + void avInvite(int friendId, int callIndex, bool video); void avStart(int friendId, int callIndex, bool video); void avCancel(int friendId, int callIndex); diff --git a/widget/form/chatform.cpp b/widget/form/chatform.cpp index 33e32879a..f8b950b7b 100644 --- a/widget/form/chatform.cpp +++ b/widget/form/chatform.cpp @@ -51,6 +51,7 @@ ChatForm::ChatForm(Friend* chatFriend) connect(msgEdit, &ChatTextEdit::enterPressed, this, &ChatForm::onSendTriggered); connect(micButton, SIGNAL(clicked()), this, SLOT(onMicMuteToggle())); connect(chatWidget, &ChatAreaWidget::onFileTranfertInterract, this, &ChatForm::onFileTansBtnClicked); + connect(Core::getInstance(), &Core::fileSendFailed, this, &ChatForm::onFileSendFailed); } ChatForm::~ChatForm() @@ -455,3 +456,11 @@ void ChatForm::onFileTansBtnClicked(QString widgetName, QString buttonName) else qDebug() << "no filetransferwidget: " << id; } + +void ChatForm::onFileSendFailed(int FriendId, const QString &fname) +{ + if (FriendId != f->friendId) + return; + + addSystemInfoMessage("File: \"" + fname + "\" failed to send.", "red"); +} diff --git a/widget/form/chatform.h b/widget/form/chatform.h index 93bc2d6b4..43681562c 100644 --- a/widget/form/chatform.h +++ b/widget/form/chatform.h @@ -65,6 +65,7 @@ private slots: void onHangupCallTriggered(); void onCancelCallTriggered(); void onFileTansBtnClicked(QString widgetName, QString buttonName); + void onFileSendFailed(int FriendId, const QString &fname); private: Friend* f;