mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
add receive actions (no one to test with currently)
This commit is contained in:
parent
30f3866772
commit
5f106ab618
4
core.cpp
4
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*>(core)->friendMessageReceived(friendId, CString::toString(cMessage, cMessageSize));
|
||||
emit static_cast<Core*>(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*>(core)->actionReceived(friendId, CString::toString(cMessage, cMessageSize));
|
||||
emit static_cast<Core*>(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)
|
||||
|
|
4
core.h
4
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);
|
||||
|
|
2
qtox.pro
2
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
|
||||
|
|
|
@ -9,6 +9,11 @@ div.message {
|
|||
font: @big;
|
||||
}
|
||||
|
||||
div.action {
|
||||
color: @blue;
|
||||
font: @big;
|
||||
}
|
||||
|
||||
div.date {
|
||||
color: @black;
|
||||
font: @big;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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:
|
||||
|
|
68
widget/tool/chatactions/actionaction.cpp
Normal file
68
widget/tool/chatactions/actionaction.cpp
Normal file
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
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 "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("<div class=action>-*-</div>");
|
||||
}
|
||||
|
||||
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("<a href=\"%1\">%1</a>").arg(url);
|
||||
message_.replace(offset, exp.cap().length(), htmledUrl);
|
||||
|
||||
offset += htmledUrl.length();
|
||||
}
|
||||
|
||||
return QString("<div class=action>%1 %2</div>").arg(name).arg(message_);
|
||||
}
|
35
widget/tool/chatactions/actionaction.h
Normal file
35
widget/tool/chatactions/actionaction.h
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
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 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
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue
Block a user