From 30e2afcc92886d37e003a5e6b76bf718cba52f88 Mon Sep 17 00:00:00 2001 From: dubslow Date: Mon, 20 Oct 2014 06:05:45 -0500 Subject: [PATCH] add alerts on user mention (could use some tweaking, but is plenty fine for now) --- qtox.pro | 2 + src/misc/style.cpp | 2 + src/misc/style.h | 1 + src/widget/form/genericchatform.cpp | 8 ++++ src/widget/form/genericchatform.h | 1 + src/widget/tool/chatactions/actionaction.cpp | 28 ++--------- src/widget/tool/chatactions/actionaction.h | 6 +-- src/widget/tool/chatactions/alertaction.cpp | 47 +++++++++++++++++++ src/widget/tool/chatactions/alertaction.h | 35 ++++++++++++++ src/widget/tool/chatactions/messageaction.cpp | 17 ++++--- src/widget/tool/chatactions/messageaction.h | 3 +- src/widget/widget.cpp | 11 +++-- ui/chatArea/innerStyle.css | 14 ++++++ 13 files changed, 138 insertions(+), 37 deletions(-) create mode 100644 src/widget/tool/chatactions/alertaction.cpp create mode 100644 src/widget/tool/chatactions/alertaction.h diff --git a/qtox.pro b/qtox.pro index 88ca5339e..0d0019c91 100644 --- a/qtox.pro +++ b/qtox.pro @@ -135,6 +135,7 @@ HEADERS += src/widget/form/addfriendform.h \ src/widget/tool/chatactions/filetransferaction.h \ src/widget/tool/chatactions/systemmessageaction.h \ src/widget/tool/chatactions/actionaction.h \ + src/widget/tool/chatactions/alertaction.h \ src/widget/maskablepixmapwidget.h \ src/videosource.h \ src/cameraworker.h \ @@ -184,6 +185,7 @@ SOURCES += \ src/widget/tool/chatactions/filetransferaction.cpp \ src/widget/tool/chatactions/systemmessageaction.cpp \ src/widget/tool/chatactions/actionaction.cpp \ + src/widget/tool/chatactions/alertaction.cpp \ src/widget/maskablepixmapwidget.cpp \ src/cameraworker.cpp \ src/widget/videosurface.cpp \ diff --git a/src/misc/style.cpp b/src/misc/style.cpp index 70100270f..e9dec32e3 100644 --- a/src/misc/style.cpp +++ b/src/misc/style.cpp @@ -70,6 +70,7 @@ QColor Style::getColor(Style::ColorPalette entry) QColor("#414141").lighter(120), QColor("#d1d1d1"), QColor("#ffffff"), + QColor("#ff7700"), }; return palette[entry]; @@ -108,6 +109,7 @@ QString Style::resolve(QString qss) {"@mediumGreyLight", getColor(MediumGreyLight).name()}, {"@lightGrey", getColor(LightGrey).name()}, {"@white", getColor(White).name()}, + {"@orange", getColor(Orange).name()}, // fonts {"@extraBig", qssifyFont(getFont(ExtraBig))}, diff --git a/src/misc/style.h b/src/misc/style.h index a07064e04..e818b2ddb 100644 --- a/src/misc/style.h +++ b/src/misc/style.h @@ -37,6 +37,7 @@ public: MediumGreyLight, LightGrey, White, + Orange, }; enum Font diff --git a/src/widget/form/genericchatform.cpp b/src/widget/form/genericchatform.cpp index bdb764777..bcac25589 100644 --- a/src/widget/form/genericchatform.cpp +++ b/src/widget/form/genericchatform.cpp @@ -25,6 +25,7 @@ #include "src/widget/tool/chatactions/messageaction.h" #include "src/widget/tool/chatactions/systemmessageaction.h" #include "src/widget/tool/chatactions/actionaction.h" +#include "src/widget/tool/chatactions/alertaction.h" #include "src/widget/chatareawidget.h" #include "src/widget/tool/chattextedit.h" #include "src/widget/maskablepixmapwidget.h" @@ -193,6 +194,13 @@ void GenericChatForm::addMessage(QString author, QString message, bool isAction, 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() { // don't show the smiley selection widget if there are no smileys available diff --git a/src/widget/form/genericchatform.h b/src/widget/form/genericchatform.h index 3f05639bc..5782823a6 100644 --- a/src/widget/form/genericchatform.h +++ b/src/widget/form/genericchatform.h @@ -45,6 +45,7 @@ public: virtual void setName(const QString &newName); virtual void show(Ui::MainWindow &ui); 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()); int getNumberOfMessages(); diff --git a/src/widget/tool/chatactions/actionaction.cpp b/src/widget/tool/chatactions/actionaction.cpp index 3facb978c..995b89e9c 100644 --- a/src/widget/tool/chatactions/actionaction.cpp +++ b/src/widget/tool/chatactions/actionaction.cpp @@ -15,12 +15,11 @@ */ #include "actionaction.h" -#include "src/misc/smileypack.h" -ActionAction::ActionAction(const QString &author, const QString &message, const QString &date, const bool& me) : - ChatAction(me, author, date), - message(message) +ActionAction::ActionAction(const QString &author, QString message, const QString &date, const bool& me) : + MessageAction(author, message, date, me) { + message = name + " " + message; } void ActionAction::setup(QTextCursor cursor, QTextEdit *) @@ -45,24 +44,5 @@ QString ActionAction::getName() 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_); + return MessageAction::getMessage("action"); } diff --git a/src/widget/tool/chatactions/actionaction.h b/src/widget/tool/chatactions/actionaction.h index 08553a96e..d438f0ecd 100644 --- a/src/widget/tool/chatactions/actionaction.h +++ b/src/widget/tool/chatactions/actionaction.h @@ -17,12 +17,12 @@ #ifndef ACTIONACTION_H #define ACTIONACTION_H -#include "chataction.h" +#include "messageaction.h" -class ActionAction : public ChatAction +class ActionAction : public MessageAction { 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 QString getMessage(); virtual QString getName(); diff --git a/src/widget/tool/chatactions/alertaction.cpp b/src/widget/tool/chatactions/alertaction.cpp new file mode 100644 index 000000000..b62c1896e --- /dev/null +++ b/src/widget/tool/chatactions/alertaction.cpp @@ -0,0 +1,47 @@ +/* + 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 "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("
%2
").arg("alert_name").arg(toHtmlChars(name)); +} +*/ +QString AlertAction::getMessage() +{ + return MessageAction::getMessage("alert"); +} diff --git a/src/widget/tool/chatactions/alertaction.h b/src/widget/tool/chatactions/alertaction.h new file mode 100644 index 000000000..64e00e6bf --- /dev/null +++ b/src/widget/tool/chatactions/alertaction.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 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 diff --git a/src/widget/tool/chatactions/messageaction.cpp b/src/widget/tool/chatactions/messageaction.cpp index 4a8b6962b..8058aa56e 100644 --- a/src/widget/tool/chatactions/messageaction.cpp +++ b/src/widget/tool/chatactions/messageaction.cpp @@ -38,7 +38,7 @@ void MessageAction::setup(QTextCursor cursor, QTextEdit *) date.squeeze(); } -QString MessageAction::getMessage() +QString MessageAction::getMessage(QString div) { QString message_ = SmileyPack::getInstance().smileyfied(toHtmlChars(message)); @@ -65,14 +65,19 @@ QString MessageAction::getMessage() for (QString& s : messageLines) { if (QRegExp("^[ ]*>.*").exactMatch(s)) - message_ += ">" + s.right(s.length()-4) + "
"; + message_ += "" + s.right(s.length()-4) + "
"; else message_ += s + "
"; } message_ = message_.left(message_.length()-4); - if (isMe) - return QString("
" + message_ + "
"); - else - return QString("
" + message_ + "
"); + return QString(QString("
").arg(div) + message_ + "
"); +} + +QString MessageAction::getMessage() +{ + if (isMe) + return getMessage("message_me"); + else + return getMessage("message"); } diff --git a/src/widget/tool/chatactions/messageaction.h b/src/widget/tool/chatactions/messageaction.h index aa32801eb..c5ba63de3 100644 --- a/src/widget/tool/chatactions/messageaction.h +++ b/src/widget/tool/chatactions/messageaction.h @@ -25,9 +25,10 @@ public: MessageAction(const QString &author, const QString &message, const QString &date, const bool &me); virtual ~MessageAction(){;} virtual QString getMessage(); + virtual QString getMessage(QString div); virtual void setup(QTextCursor cursor, QTextEdit*) override; -private: +protected: QString message; }; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index fdc3465d8..dd34374d5 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -750,14 +750,19 @@ void Widget::onGroupMessageReceived(int groupnumber, const QString& message, con if (!g) 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(g->widget) != activeChatroomWidget) || isMinimized() || !isActiveWindow()) { g->hasNewMessages = 1; - newMessageAlert(); // sound alert on any message, not just naming user - if (message.contains(core->getUsername(), Qt::CaseInsensitive)) + if (targeted) { + newMessageAlert(); g->userWasMentioned = 1; // useful for highlighting line or desktop notifications } g->widget->updateStatusLight(); diff --git a/ui/chatArea/innerStyle.css b/ui/chatArea/innerStyle.css index b5c537362..1b5e2e844 100644 --- a/ui/chatArea/innerStyle.css +++ b/ui/chatArea/innerStyle.css @@ -67,6 +67,20 @@ div.red { 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 { margin-top: 0px; margin-bottom: 0px;