1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Merge pull request #364 from dubslow/master

Add actions
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-10-03 00:55:07 +02:00
commit 6821bed50d
11 changed files with 144 additions and 17 deletions

View File

@ -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
View File

@ -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);

View File

@ -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

View File

@ -1,6 +1,7 @@
div.name {
color: @black;
font: @big;
font: @bigBold;
font-weight: bold; /* @bigBold doesn't actually work */
}
div.message {
@ -8,6 +9,11 @@ div.message {
font: @big;
}
div.action {
color: #1818FF;
font: @big;
}
div.date {
color: @black;
font: @big;
@ -19,12 +25,12 @@ div.name_me {
}
div.message_me {
color: @mediumGrey;
color: @black;
font: @big;
}
div.date_me {
color: @mediumGrey;
color: @black;
font: @big;
}

View File

@ -86,9 +86,18 @@ void ChatForm::onSendTriggered()
if (msg.isEmpty())
return;
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();
addMessage(name, msg);
emit sendMessage(f->friendId, msg);
}
void ChatForm::onAttachClicked()

View File

@ -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,21 @@ 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));
previousName = ""; // next msg has a name regardless
return;
}
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;
}

View File

@ -44,11 +44,12 @@ 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:
void sendMessage(int, QString);
void sendAction(int, QString);
public slots:
void focusInput();

View 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_);
}

View 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

View File

@ -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(chatroomWidgetClicked(GenericChatroomWidget*)), newfriend->chatForm, SLOT(focusInput()));
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(answerCall(int)), core, SLOT(answerCall(int)));
connect(newfriend->chatForm, SIGNAL(hangupCall(int)), core, SLOT(hangupCall(int)));
@ -545,13 +546,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)
{

View File

@ -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);