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

add alerts on user mention (could use some tweaking, but is plenty fine for now)

This commit is contained in:
dubslow 2014-10-20 06:05:45 -05:00
parent 5b85f79055
commit 30e2afcc92
13 changed files with 138 additions and 37 deletions

View File

@ -135,6 +135,7 @@ HEADERS += src/widget/form/addfriendform.h \
src/widget/tool/chatactions/filetransferaction.h \ src/widget/tool/chatactions/filetransferaction.h \
src/widget/tool/chatactions/systemmessageaction.h \ src/widget/tool/chatactions/systemmessageaction.h \
src/widget/tool/chatactions/actionaction.h \ src/widget/tool/chatactions/actionaction.h \
src/widget/tool/chatactions/alertaction.h \
src/widget/maskablepixmapwidget.h \ src/widget/maskablepixmapwidget.h \
src/videosource.h \ src/videosource.h \
src/cameraworker.h \ src/cameraworker.h \
@ -184,6 +185,7 @@ SOURCES += \
src/widget/tool/chatactions/filetransferaction.cpp \ src/widget/tool/chatactions/filetransferaction.cpp \
src/widget/tool/chatactions/systemmessageaction.cpp \ src/widget/tool/chatactions/systemmessageaction.cpp \
src/widget/tool/chatactions/actionaction.cpp \ src/widget/tool/chatactions/actionaction.cpp \
src/widget/tool/chatactions/alertaction.cpp \
src/widget/maskablepixmapwidget.cpp \ src/widget/maskablepixmapwidget.cpp \
src/cameraworker.cpp \ src/cameraworker.cpp \
src/widget/videosurface.cpp \ src/widget/videosurface.cpp \

View File

@ -70,6 +70,7 @@ QColor Style::getColor(Style::ColorPalette entry)
QColor("#414141").lighter(120), QColor("#414141").lighter(120),
QColor("#d1d1d1"), QColor("#d1d1d1"),
QColor("#ffffff"), QColor("#ffffff"),
QColor("#ff7700"),
}; };
return palette[entry]; return palette[entry];
@ -108,6 +109,7 @@ QString Style::resolve(QString qss)
{"@mediumGreyLight", getColor(MediumGreyLight).name()}, {"@mediumGreyLight", getColor(MediumGreyLight).name()},
{"@lightGrey", getColor(LightGrey).name()}, {"@lightGrey", getColor(LightGrey).name()},
{"@white", getColor(White).name()}, {"@white", getColor(White).name()},
{"@orange", getColor(Orange).name()},
// fonts // fonts
{"@extraBig", qssifyFont(getFont(ExtraBig))}, {"@extraBig", qssifyFont(getFont(ExtraBig))},

View File

@ -37,6 +37,7 @@ public:
MediumGreyLight, MediumGreyLight,
LightGrey, LightGrey,
White, White,
Orange,
}; };
enum Font enum Font

View File

@ -25,6 +25,7 @@
#include "src/widget/tool/chatactions/messageaction.h" #include "src/widget/tool/chatactions/messageaction.h"
#include "src/widget/tool/chatactions/systemmessageaction.h" #include "src/widget/tool/chatactions/systemmessageaction.h"
#include "src/widget/tool/chatactions/actionaction.h" #include "src/widget/tool/chatactions/actionaction.h"
#include "src/widget/tool/chatactions/alertaction.h"
#include "src/widget/chatareawidget.h" #include "src/widget/chatareawidget.h"
#include "src/widget/tool/chattextedit.h" #include "src/widget/tool/chattextedit.h"
#include "src/widget/maskablepixmapwidget.h" #include "src/widget/maskablepixmapwidget.h"
@ -193,6 +194,13 @@ void GenericChatForm::addMessage(QString author, QString message, bool isAction,
previousName = author; previousName = author;
} }
void GenericChatForm::addAlertMessage(QString author, QString message, QDateTime datetime)
{
QString date = datetime.toString(Settings::getInstance().getTimestampFormat());
chatWidget->insertMessage(new AlertAction(author, message, date));
previousName = author;
}
void GenericChatForm::onEmoteButtonClicked() void GenericChatForm::onEmoteButtonClicked()
{ {
// don't show the smiley selection widget if there are no smileys available // don't show the smiley selection widget if there are no smileys available

View File

@ -45,6 +45,7 @@ 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, bool isAction = false, QDateTime datetime=QDateTime::currentDateTime()); void addMessage(QString author, QString message, bool isAction = false, QDateTime datetime=QDateTime::currentDateTime());
void addAlertMessage(QString author, QString message, 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());
int getNumberOfMessages(); int getNumberOfMessages();

View File

@ -15,12 +15,11 @@
*/ */
#include "actionaction.h" #include "actionaction.h"
#include "src/misc/smileypack.h"
ActionAction::ActionAction(const QString &author, const QString &message, const QString &date, const bool& me) : ActionAction::ActionAction(const QString &author, QString message, const QString &date, const bool& me) :
ChatAction(me, author, date), MessageAction(author, message, date, me)
message(message)
{ {
message = name + " " + message;
} }
void ActionAction::setup(QTextCursor cursor, QTextEdit *) void ActionAction::setup(QTextCursor cursor, QTextEdit *)
@ -45,24 +44,5 @@ QString ActionAction::getName()
QString ActionAction::getMessage() QString ActionAction::getMessage()
{ {
QString message_ = SmileyPack::getInstance().smileyfied(toHtmlChars(message)); return MessageAction::getMessage("action");
// 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

@ -17,12 +17,12 @@
#ifndef ACTIONACTION_H #ifndef ACTIONACTION_H
#define ACTIONACTION_H #define ACTIONACTION_H
#include "chataction.h" #include "messageaction.h"
class ActionAction : public ChatAction class ActionAction : public MessageAction
{ {
public: public:
ActionAction(const QString &author, const QString &message, const QString& date, const bool&); ActionAction(const QString &author, QString message, const QString& date, const bool&);
virtual ~ActionAction(){;} virtual ~ActionAction(){;}
virtual QString getMessage(); virtual QString getMessage();
virtual QString getName(); virtual QString getName();

View File

@ -0,0 +1,47 @@
/*
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 "alertaction.h"
AlertAction::AlertAction(const QString &author, const QString &message, const QString &date) :
MessageAction(author, message, date, false)
{
}
void AlertAction::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 AlertAction::getName()
{
return QString("<div class=%1>%2</div>").arg("alert_name").arg(toHtmlChars(name));
}
*/
QString AlertAction::getMessage()
{
return MessageAction::getMessage("alert");
}

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 ALERTACTION_H
#define ALERTACTION_H
#include "messageaction.h"
class AlertAction : public MessageAction
{
public:
AlertAction(const QString &author, const QString &message, const QString& date);
virtual ~AlertAction(){;}
virtual QString getMessage();
//virtual QString getName(); only do the message for now; preferably would do the whole row
virtual void setup(QTextCursor cursor, QTextEdit*) override;
private:
QString message;
};
#endif // MESSAGEACTION_H

View File

@ -38,7 +38,7 @@ void MessageAction::setup(QTextCursor cursor, QTextEdit *)
date.squeeze(); date.squeeze();
} }
QString MessageAction::getMessage() QString MessageAction::getMessage(QString div)
{ {
QString message_ = SmileyPack::getInstance().smileyfied(toHtmlChars(message)); QString message_ = SmileyPack::getInstance().smileyfied(toHtmlChars(message));
@ -65,14 +65,19 @@ QString MessageAction::getMessage()
for (QString& s : messageLines) for (QString& s : messageLines)
{ {
if (QRegExp("^[ ]*&gt;.*").exactMatch(s)) if (QRegExp("^[ ]*&gt;.*").exactMatch(s))
message_ += "<span class=quote>>" + s.right(s.length()-4) + "</span><br/>"; message_ += "<span class=quote>" + s.right(s.length()-4) + "</span><br/>";
else else
message_ += s + "<br/>"; message_ += s + "<br/>";
} }
message_ = message_.left(message_.length()-4); message_ = message_.left(message_.length()-4);
if (isMe) return QString(QString("<div class=%1>").arg(div) + message_ + "</div>");
return QString("<div class=message_me>" + message_ + "</div>"); }
else
return QString("<div class=message>" + message_ + "</div>"); QString MessageAction::getMessage()
{
if (isMe)
return getMessage("message_me");
else
return getMessage("message");
} }

View File

@ -25,9 +25,10 @@ public:
MessageAction(const QString &author, const QString &message, const QString &date, const bool &me); MessageAction(const QString &author, const QString &message, const QString &date, const bool &me);
virtual ~MessageAction(){;} virtual ~MessageAction(){;}
virtual QString getMessage(); virtual QString getMessage();
virtual QString getMessage(QString div);
virtual void setup(QTextCursor cursor, QTextEdit*) override; virtual void setup(QTextCursor cursor, QTextEdit*) override;
private: protected:
QString message; QString message;
}; };

View File

@ -750,14 +750,19 @@ void Widget::onGroupMessageReceived(int groupnumber, const QString& message, con
if (!g) if (!g)
return; return;
g->chatForm->addMessage(author, message); QString name = core->getUsername();
bool targeted = (author != name) && message.contains(name, Qt::CaseInsensitive);
if (targeted)
g->chatForm->addAlertMessage(author, message);
else
g->chatForm->addMessage(author, message);
if ((static_cast<GenericChatroomWidget*>(g->widget) != activeChatroomWidget) || isMinimized() || !isActiveWindow()) if ((static_cast<GenericChatroomWidget*>(g->widget) != activeChatroomWidget) || isMinimized() || !isActiveWindow())
{ {
g->hasNewMessages = 1; g->hasNewMessages = 1;
newMessageAlert(); // sound alert on any message, not just naming user if (targeted)
if (message.contains(core->getUsername(), Qt::CaseInsensitive))
{ {
newMessageAlert();
g->userWasMentioned = 1; // useful for highlighting line or desktop notifications g->userWasMentioned = 1; // useful for highlighting line or desktop notifications
} }
g->widget->updateStatusLight(); g->widget->updateStatusLight();

View File

@ -67,6 +67,20 @@ div.red {
font: @small; font: @small;
} }
div.alert {
margin-left: 0px;
margin-right: 0px;
color: @black;
background-color: @orange;
font: @big;
}
div.alert_name {
color: @black;
background-color: @orange;
font: @bigBold;
}
div.button { div.button {
margin-top: 0px; margin-top: 0px;
margin-bottom: 0px; margin-bottom: 0px;