From 5f106ab6183b202e35f3e712a779249c91d7ea68 Mon Sep 17 00:00:00 2001 From: dubslow Date: Thu, 2 Oct 2014 01:01:23 -0500 Subject: [PATCH] add receive actions (no one to test with currently) --- core.cpp | 4 +- core.h | 4 +- qtox.pro | 2 + ui/chatArea/innerStyle.css | 5 ++ widget/form/genericchatform.cpp | 9 ++-- widget/form/genericchatform.h | 2 +- widget/tool/chatactions/actionaction.cpp | 68 ++++++++++++++++++++++++ widget/tool/chatactions/actionaction.h | 35 ++++++++++++ widget/widget.cpp | 4 +- widget/widget.h | 2 +- 10 files changed, 123 insertions(+), 12 deletions(-) create mode 100644 widget/tool/chatactions/actionaction.cpp create mode 100644 widget/tool/chatactions/actionaction.h diff --git a/core.cpp b/core.cpp index 53214dd3d..f6b7a2a5c 100644 --- a/core.cpp +++ b/core.cpp @@ -313,7 +313,7 @@ void Core::onFriendRequest(Tox*/* tox*/, const uint8_t* cUserId, const uint8_t* void Core::onFriendMessage(Tox*/* tox*/, int friendId, const uint8_t* cMessage, uint16_t cMessageSize, void* core) { - emit static_cast(core)->friendMessageReceived(friendId, CString::toString(cMessage, cMessageSize)); + emit static_cast(core)->friendMessageReceived(friendId, CString::toString(cMessage, cMessageSize), false); } void Core::onFriendNameChange(Tox*/* tox*/, int friendId, const uint8_t* cName, uint16_t cNameSize, void* core) @@ -393,7 +393,7 @@ void Core::onConnectionStatusChanged(Tox*/* tox*/, int friendId, uint8_t status, void Core::onAction(Tox*/* tox*/, int friendId, const uint8_t *cMessage, uint16_t cMessageSize, void *core) { - emit static_cast(core)->actionReceived(friendId, CString::toString(cMessage, cMessageSize)); + emit static_cast(core)->friendMessageReceived(friendId, CString::toString(cMessage, cMessageSize), true); } void Core::onGroupInvite(Tox*, int friendnumber, const uint8_t *group_public_key, uint16_t length,void *core) diff --git a/core.h b/core.h index 71692c3b2..b1b8c3f43 100644 --- a/core.h +++ b/core.h @@ -99,7 +99,7 @@ signals: void disconnected(); void friendRequestReceived(const QString& userId, const QString& message); - void friendMessageReceived(int friendId, const QString& message); + void friendMessageReceived(int friendId, const QString& message, bool isAction); void friendAdded(int friendId, const QString& userId); @@ -137,8 +137,6 @@ signals: void failedToSetStatus(Status status); void failedToSetTyping(bool typing); - void actionReceived(int friendId, const QString& acionMessage); - void failedToStart(); void fileSendStarted(ToxFile file); diff --git a/qtox.pro b/qtox.pro index 4c4db4492..e08e1f24e 100644 --- a/qtox.pro +++ b/qtox.pro @@ -119,6 +119,7 @@ HEADERS += widget/form/addfriendform.h \ widget/tool/chatactions/messageaction.h \ widget/tool/chatactions/filetransferaction.h \ widget/tool/chatactions/systemmessageaction.h \ + widget/tool/chatactions/actionaction.h \ widget/maskablepixmapwidget.h SOURCES += \ @@ -160,4 +161,5 @@ SOURCES += \ widget/tool/chatactions/messageaction.cpp \ widget/tool/chatactions/filetransferaction.cpp \ widget/tool/chatactions/systemmessageaction.cpp \ + widget/tool/chatactions/actionaction.cpp \ widget/maskablepixmapwidget.cpp diff --git a/ui/chatArea/innerStyle.css b/ui/chatArea/innerStyle.css index 771068a1d..5775f41f3 100644 --- a/ui/chatArea/innerStyle.css +++ b/ui/chatArea/innerStyle.css @@ -9,6 +9,11 @@ div.message { font: @big; } +div.action { + color: @blue; + font: @big; +} + div.date { color: @black; font: @big; diff --git a/widget/form/genericchatform.cpp b/widget/form/genericchatform.cpp index a7bcb5e2b..923089728 100644 --- a/widget/form/genericchatform.cpp +++ b/widget/form/genericchatform.cpp @@ -24,6 +24,7 @@ #include "misc/settings.h" #include "widget/tool/chatactions/messageaction.h" #include "widget/tool/chatactions/systemmessageaction.h" +#include "widget/tool/chatactions/actionaction.h" #include "widget/chatareawidget.h" #include "widget/tool/chattextedit.h" #include "widget/maskablepixmapwidget.h" @@ -166,15 +167,17 @@ void GenericChatForm::onSaveLogClicked() file.close(); } -void GenericChatForm::addMessage(QString author, QString message, QDateTime datetime) +void GenericChatForm::addMessage(QString author, QString message, bool isAction, QDateTime datetime) { QString date = datetime.toString(Settings::getInstance().getTimestampFormat()); bool isMe = (author == Widget::getInstance()->getUsername()); - if (previousName == author) + if (isAction) + chatWidget->insertMessage(new ActionAction (getElidedName(author), message, date, isMe)); + else if (previousName == author) chatWidget->insertMessage(new MessageAction("", message, date, isMe)); else - chatWidget->insertMessage(new MessageAction(getElidedName(author) , message, date, isMe)); + chatWidget->insertMessage(new MessageAction(getElidedName(author), message, date, isMe)); previousName = author; } diff --git a/widget/form/genericchatform.h b/widget/form/genericchatform.h index 2111bcdf9..863c90a0d 100644 --- a/widget/form/genericchatform.h +++ b/widget/form/genericchatform.h @@ -44,7 +44,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 addMessage(QString author, QString message, bool isAction = false, QDateTime datetime=QDateTime::currentDateTime()); void addSystemInfoMessage(const QString &message, const QString &type, const QDateTime &datetime=QDateTime::currentDateTime()); signals: diff --git a/widget/tool/chatactions/actionaction.cpp b/widget/tool/chatactions/actionaction.cpp new file mode 100644 index 000000000..754966107 --- /dev/null +++ b/widget/tool/chatactions/actionaction.cpp @@ -0,0 +1,68 @@ +/* + 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 "actionaction.h" +#include "misc/smileypack.h" + +ActionAction::ActionAction(const QString &author, const QString &message, const QString &date, const bool& me) : + ChatAction(me, author, date), + message(message) +{ +} + +void ActionAction::setup(QTextCursor cursor, QTextEdit *) +{ + // 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 ActionAction::getName() +{ + return QString("
-*-
"); +} + +QString ActionAction::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(); + } + + return QString("
%1 %2
").arg(name).arg(message_); +} diff --git a/widget/tool/chatactions/actionaction.h b/widget/tool/chatactions/actionaction.h new file mode 100644 index 000000000..ec4e5f4a8 --- /dev/null +++ b/widget/tool/chatactions/actionaction.h @@ -0,0 +1,35 @@ +/* + 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 ACTIONACTION_H +#define ACTIONACTION_H + +#include "widget/tool/chatactions/chataction.h" + +class ActionAction : public ChatAction +{ +public: + ActionAction(const QString &author, const QString &message, const QString& date, const bool&); + virtual ~ActionAction(){;} + virtual QString getMessage(); + virtual QString getName(); + virtual void setup(QTextCursor cursor, QTextEdit*) override; + +private: + QString message; +}; + +#endif // MESSAGEACTION_H diff --git a/widget/widget.cpp b/widget/widget.cpp index e2c4770e9..e16a33c88 100644 --- a/widget/widget.cpp +++ b/widget/widget.cpp @@ -545,13 +545,13 @@ void Widget::onChatroomWidgetClicked(GenericChatroomWidget *widget) widget->updateStatusLight(); } -void Widget::onFriendMessageReceived(int friendId, const QString& message) +void Widget::onFriendMessageReceived(int friendId, const QString& message, bool isAction) { Friend* f = FriendList::findFriend(friendId); if (!f) return; - f->chatForm->addMessage(f->getName(), message); + f->chatForm->addMessage(f->getName(), message, isAction); if (activeChatroomWidget != nullptr) { diff --git a/widget/widget.h b/widget/widget.h index 5141e49f0..41289c9cd 100644 --- a/widget/widget.h +++ b/widget/widget.h @@ -93,7 +93,7 @@ private slots: void onFriendStatusMessageChanged(int friendId, const QString& message); void onFriendUsernameChanged(int friendId, const QString& username); void onChatroomWidgetClicked(GenericChatroomWidget *); - void onFriendMessageReceived(int friendId, const QString& message); + void onFriendMessageReceived(int friendId, const QString& message, bool isAction); void onFriendRequestReceived(const QString& userId, const QString& message); void onEmptyGroupCreated(int groupId); void onGroupInviteReceived(int32_t friendId, const uint8_t *publicKey,uint16_t length);