mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
commit
6821bed50d
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)
|
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)
|
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)
|
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)
|
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 disconnected();
|
||||||
|
|
||||||
void friendRequestReceived(const QString& userId, const QString& message);
|
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);
|
void friendAdded(int friendId, const QString& userId);
|
||||||
|
|
||||||
|
@ -137,8 +137,6 @@ signals:
|
||||||
void failedToSetStatus(Status status);
|
void failedToSetStatus(Status status);
|
||||||
void failedToSetTyping(bool typing);
|
void failedToSetTyping(bool typing);
|
||||||
|
|
||||||
void actionReceived(int friendId, const QString& acionMessage);
|
|
||||||
|
|
||||||
void failedToStart();
|
void failedToStart();
|
||||||
|
|
||||||
void fileSendStarted(ToxFile file);
|
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/messageaction.h \
|
||||||
widget/tool/chatactions/filetransferaction.h \
|
widget/tool/chatactions/filetransferaction.h \
|
||||||
widget/tool/chatactions/systemmessageaction.h \
|
widget/tool/chatactions/systemmessageaction.h \
|
||||||
|
widget/tool/chatactions/actionaction.h \
|
||||||
widget/maskablepixmapwidget.h
|
widget/maskablepixmapwidget.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
@ -160,4 +161,5 @@ SOURCES += \
|
||||||
widget/tool/chatactions/messageaction.cpp \
|
widget/tool/chatactions/messageaction.cpp \
|
||||||
widget/tool/chatactions/filetransferaction.cpp \
|
widget/tool/chatactions/filetransferaction.cpp \
|
||||||
widget/tool/chatactions/systemmessageaction.cpp \
|
widget/tool/chatactions/systemmessageaction.cpp \
|
||||||
|
widget/tool/chatactions/actionaction.cpp \
|
||||||
widget/maskablepixmapwidget.cpp
|
widget/maskablepixmapwidget.cpp
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
div.name {
|
div.name {
|
||||||
color: @black;
|
color: @black;
|
||||||
font: @big;
|
font: @bigBold;
|
||||||
|
font-weight: bold; /* @bigBold doesn't actually work */
|
||||||
}
|
}
|
||||||
|
|
||||||
div.message {
|
div.message {
|
||||||
|
@ -8,6 +9,11 @@ div.message {
|
||||||
font: @big;
|
font: @big;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.action {
|
||||||
|
color: #1818FF;
|
||||||
|
font: @big;
|
||||||
|
}
|
||||||
|
|
||||||
div.date {
|
div.date {
|
||||||
color: @black;
|
color: @black;
|
||||||
font: @big;
|
font: @big;
|
||||||
|
@ -19,12 +25,12 @@ div.name_me {
|
||||||
}
|
}
|
||||||
|
|
||||||
div.message_me {
|
div.message_me {
|
||||||
color: @mediumGrey;
|
color: @black;
|
||||||
font: @big;
|
font: @big;
|
||||||
}
|
}
|
||||||
|
|
||||||
div.date_me {
|
div.date_me {
|
||||||
color: @mediumGrey;
|
color: @black;
|
||||||
font: @big;
|
font: @big;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,9 +86,18 @@ void ChatForm::onSendTriggered()
|
||||||
if (msg.isEmpty())
|
if (msg.isEmpty())
|
||||||
return;
|
return;
|
||||||
QString name = Widget::getInstance()->getUsername();
|
QString name = Widget::getInstance()->getUsername();
|
||||||
|
if (msg.startsWith("/me "))
|
||||||
|
{
|
||||||
|
msg = msg.right(msg.length() - 4);
|
||||||
|
addMessage(name, msg, true);
|
||||||
|
emit sendAction(f->friendId, msg);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
addMessage(name, msg, false);
|
||||||
|
emit sendMessage(f->friendId, msg);
|
||||||
|
}
|
||||||
msgEdit->clear();
|
msgEdit->clear();
|
||||||
addMessage(name, msg);
|
|
||||||
emit sendMessage(f->friendId, msg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChatForm::onAttachClicked()
|
void ChatForm::onAttachClicked()
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "misc/settings.h"
|
#include "misc/settings.h"
|
||||||
#include "widget/tool/chatactions/messageaction.h"
|
#include "widget/tool/chatactions/messageaction.h"
|
||||||
#include "widget/tool/chatactions/systemmessageaction.h"
|
#include "widget/tool/chatactions/systemmessageaction.h"
|
||||||
|
#include "widget/tool/chatactions/actionaction.h"
|
||||||
#include "widget/chatareawidget.h"
|
#include "widget/chatareawidget.h"
|
||||||
#include "widget/tool/chattextedit.h"
|
#include "widget/tool/chattextedit.h"
|
||||||
#include "widget/maskablepixmapwidget.h"
|
#include "widget/maskablepixmapwidget.h"
|
||||||
|
@ -166,15 +167,21 @@ void GenericChatForm::onSaveLogClicked()
|
||||||
file.close();
|
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());
|
QString date = datetime.toString(Settings::getInstance().getTimestampFormat());
|
||||||
bool isMe = (author == Widget::getInstance()->getUsername());
|
bool isMe = (author == Widget::getInstance()->getUsername());
|
||||||
|
|
||||||
if (previousName == author)
|
if (isAction)
|
||||||
|
{
|
||||||
|
chatWidget->insertMessage(new ActionAction (getElidedName(author), message, date, isMe));
|
||||||
|
previousName = ""; // next msg has a name regardless
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (previousName == author)
|
||||||
chatWidget->insertMessage(new MessageAction("", message, date, isMe));
|
chatWidget->insertMessage(new MessageAction("", message, date, isMe));
|
||||||
else
|
else
|
||||||
chatWidget->insertMessage(new MessageAction(getElidedName(author) , message, date, isMe));
|
chatWidget->insertMessage(new MessageAction(getElidedName(author), message, date, isMe));
|
||||||
|
|
||||||
previousName = author;
|
previousName = author;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,11 +44,12 @@ public:
|
||||||
|
|
||||||
virtual void setName(const QString &newName);
|
virtual void setName(const QString &newName);
|
||||||
virtual void show(Ui::MainWindow &ui);
|
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());
|
void addSystemInfoMessage(const QString &message, const QString &type, const QDateTime &datetime=QDateTime::currentDateTime());
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void sendMessage(int, QString);
|
void sendMessage(int, QString);
|
||||||
|
void sendAction(int, QString);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void focusInput();
|
void focusInput();
|
||||||
|
|
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
|
|
@ -455,6 +455,7 @@ void Widget::addFriend(int friendId, const QString &userId)
|
||||||
connect(newfriend->widget, SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
|
connect(newfriend->widget, SIGNAL(copyFriendIdToClipboard(int)), this, SLOT(copyFriendIdToClipboard(int)));
|
||||||
connect(newfriend->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->chatForm, SLOT(focusInput()));
|
connect(newfriend->widget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->chatForm, SLOT(focusInput()));
|
||||||
connect(newfriend->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString)));
|
connect(newfriend->chatForm, SIGNAL(sendMessage(int,QString)), core, SLOT(sendMessage(int,QString)));
|
||||||
|
connect(newfriend->chatForm, &GenericChatForm::sendAction, core, &Core::sendAction);
|
||||||
connect(newfriend->chatForm, SIGNAL(sendFile(int32_t, QString, QString, long long)), core, SLOT(sendFile(int32_t, QString, QString, long long)));
|
connect(newfriend->chatForm, SIGNAL(sendFile(int32_t, QString, QString, long long)), core, SLOT(sendFile(int32_t, QString, QString, long long)));
|
||||||
connect(newfriend->chatForm, SIGNAL(answerCall(int)), core, SLOT(answerCall(int)));
|
connect(newfriend->chatForm, SIGNAL(answerCall(int)), core, SLOT(answerCall(int)));
|
||||||
connect(newfriend->chatForm, SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int)));
|
connect(newfriend->chatForm, SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int)));
|
||||||
|
@ -545,13 +546,13 @@ void Widget::onChatroomWidgetClicked(GenericChatroomWidget *widget)
|
||||||
widget->updateStatusLight();
|
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);
|
Friend* f = FriendList::findFriend(friendId);
|
||||||
if (!f)
|
if (!f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
f->chatForm->addMessage(f->getName(), message);
|
f->chatForm->addMessage(f->getName(), message, isAction);
|
||||||
|
|
||||||
if (activeChatroomWidget != nullptr)
|
if (activeChatroomWidget != nullptr)
|
||||||
{
|
{
|
||||||
|
|
|
@ -93,7 +93,7 @@ private slots:
|
||||||
void onFriendStatusMessageChanged(int friendId, const QString& message);
|
void onFriendStatusMessageChanged(int friendId, const QString& message);
|
||||||
void onFriendUsernameChanged(int friendId, const QString& username);
|
void onFriendUsernameChanged(int friendId, const QString& username);
|
||||||
void onChatroomWidgetClicked(GenericChatroomWidget *);
|
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 onFriendRequestReceived(const QString& userId, const QString& message);
|
||||||
void onEmptyGroupCreated(int groupId);
|
void onEmptyGroupCreated(int groupId);
|
||||||
void onGroupInviteReceived(int32_t friendId, const uint8_t *publicKey,uint16_t length);
|
void onGroupInviteReceived(int32_t friendId, const uint8_t *publicKey,uint16_t length);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user