summaryrefslogtreecommitdiffstats
path: root/Swift
diff options
context:
space:
mode:
Diffstat (limited to 'Swift')
-rw-r--r--Swift/Controllers/Highlighting/HighlightManager.cpp2
-rw-r--r--Swift/QtUI/QtWebKitChatView.cpp14
2 files changed, 7 insertions, 9 deletions
diff --git a/Swift/Controllers/Highlighting/HighlightManager.cpp b/Swift/Controllers/Highlighting/HighlightManager.cpp
index 89261af..2ca77e7 100644
--- a/Swift/Controllers/Highlighting/HighlightManager.cpp
+++ b/Swift/Controllers/Highlighting/HighlightManager.cpp
@@ -23,62 +23,60 @@
#include <boost/regex.hpp>
#include <boost/serialization/vector.hpp>
#include <Swiften/Base/Log.h>
#include <Swift/Controllers/Highlighting/HighlightConfiguration.h>
#include <Swift/Controllers/Highlighting/Highlighter.h>
#include <Swift/Controllers/SettingConstants.h>
#include <Swift/Controllers/Settings/SettingsProvider.h>
namespace Swift {
HighlightManager::HighlightManager(SettingsProvider* settings)
: settings_(settings)
, storingSettings_(false) {
highlightConfiguration_ = std::make_shared<HighlightConfiguration>();
loadSettings();
handleSettingChangedConnection_ = settings_->onSettingChanged.connect(boost::bind(&HighlightManager::handleSettingChanged, this, _1));
}
void HighlightManager::handleSettingChanged(const std::string& settingPath) {
if (!storingSettings_ && SettingConstants::HIGHLIGHT_RULES.getKey() == settingPath) {
loadSettings();
}
}
HighlightConfiguration HighlightManager::getDefaultConfig() {
HighlightConfiguration defaultConfiguration;
defaultConfiguration.playSoundOnIncomingDirectMessages = true;
defaultConfiguration.showNotificationOnIncomingDirectMessages = true;
- defaultConfiguration.ownMentionAction.setFrontColor(std::string("black"));
- defaultConfiguration.ownMentionAction.setBackColor(std::string("yellow"));
defaultConfiguration.ownMentionAction.setSoundFilePath(std::string("/sounds/message-received.wav"));
defaultConfiguration.ownMentionAction.setSystemNotificationEnabled(true);
return defaultConfiguration;
}
void HighlightManager::storeSettings() {
storingSettings_ = true; // don't reload settings while saving
settings_->storeSetting(SettingConstants::HIGHLIGHT_RULES_V2, highlightConfigurationToString(*highlightConfiguration_));
storingSettings_ = false;
}
void HighlightManager::loadSettings() {
std::string configString = settings_->getSetting(SettingConstants::HIGHLIGHT_RULES_V2);
*highlightConfiguration_ = highlightConfigurationFromString(configString);
}
Highlighter* HighlightManager::createHighlighter(NickResolver* nickResolver) {
return new Highlighter(this, nickResolver);
}
void HighlightManager::resetToDefaultConfiguration() {
*highlightConfiguration_ = getDefaultConfig();
}
HighlightConfiguration HighlightManager::highlightConfigurationFromString(const std::string& dataString) {
std::stringstream stream;
stream << dataString;
HighlightConfiguration configuration;
try {
diff --git a/Swift/QtUI/QtWebKitChatView.cpp b/Swift/QtUI/QtWebKitChatView.cpp
index 048fe99..4dd67f1 100644
--- a/Swift/QtUI/QtWebKitChatView.cpp
+++ b/Swift/QtUI/QtWebKitChatView.cpp
@@ -456,69 +456,69 @@ void QtWebKitChatView::setMUCInvitationJoined(QString id) {
void QtWebKitChatView::askDesktopToOpenFile(const QString& filename) {
QFileInfo fileInfo(filename);
if (fileInfo.exists() && fileInfo.isFile()) {
QDesktopServices::openUrl(QUrl::fromLocalFile(filename));
}
}
int QtWebKitChatView::getSnippetPositionByDate(const QDate& date) {
QWebElement message = webPage_->mainFrame()->documentElement().findFirst(".date" + date.toString(Qt::ISODate));
return message.geometry().top();
}
void QtWebKitChatView::resetTopInsertPoint() {
// TODO: Implement or refactor later.
SWIFT_LOG(error) << "Not yet implemented!" << std::endl;
}
std::string QtWebKitChatView::addMessage(
const ChatWindow::ChatMessage& message,
const std::string& senderName,
bool senderIsSelf,
std::shared_ptr<SecurityLabel> label,
const std::string& avatarPath,
const boost::posix_time::ptime& time) {
return addMessage(chatMessageToHTML(message), senderName, senderIsSelf, label, avatarPath, "", time, message.getHighlightActionSender(), ChatSnippet::getDirection(message));
}
QString QtWebKitChatView::getHighlightSpanStart(const std::string& text, const std::string& background) {
- QString ecsapeColor = QtUtilities::htmlEscape(P2QSTRING(text));
- QString escapeBackground = QtUtilities::htmlEscape(P2QSTRING(background));
- if (ecsapeColor.isEmpty()) {
- ecsapeColor = "black";
+ QString ecsapeColor;
+ QString escapeBackground;
+ if (!text.empty()) {
+ ecsapeColor = QString("color: %1").arg(QtUtilities::htmlEscape(P2QSTRING(text)));
}
- if (escapeBackground.isEmpty()) {
- escapeBackground = "yellow";
+ if (!background.empty()) {
+ escapeBackground = QString("background: %1").arg(QtUtilities::htmlEscape(P2QSTRING(background)));
}
- return QString("<span style=\"color: %1; background: %2\">").arg(ecsapeColor).arg(escapeBackground);
+ return QString("<span style=\"%1; %2;\">").arg(ecsapeColor).arg(escapeBackground);
}
QString QtWebKitChatView::getHighlightSpanStart(const HighlightAction& highlight) {
return getHighlightSpanStart(highlight.getFrontColor().get_value_or(""), highlight.getBackColor().get_value_or(""));
}
QString QtWebKitChatView::chatMessageToHTML(const ChatWindow::ChatMessage& message) {
QString result;
for (const auto& part : message.getParts()) {
std::shared_ptr<ChatWindow::ChatTextMessagePart> textPart;
std::shared_ptr<ChatWindow::ChatURIMessagePart> uriPart;
std::shared_ptr<ChatWindow::ChatEmoticonMessagePart> emoticonPart;
std::shared_ptr<ChatWindow::ChatHighlightingMessagePart> highlightPart;
if ((textPart = std::dynamic_pointer_cast<ChatWindow::ChatTextMessagePart>(part))) {
QString text = QtUtilities::htmlEscape(P2QSTRING(textPart->text));
text.replace("\n","<br/>");
result += text;
continue;
}
if ((uriPart = std::dynamic_pointer_cast<ChatWindow::ChatURIMessagePart>(part))) {
QString uri = QtUtilities::htmlEscape(P2QSTRING(uriPart->target));
result += "<a href='" + uri + "' >" + uri + "</a>";
continue;
}
if ((emoticonPart = std::dynamic_pointer_cast<ChatWindow::ChatEmoticonMessagePart>(part))) {
QString textStyle = showEmoticons_ ? "style='display:none'" : "";
QString imageStyle = showEmoticons_ ? "" : "style='display:none'";
result += "<span class='swift_emoticon_image' " + imageStyle + "><img src='" + P2QSTRING(emoticonPart->imagePath) + "'/></span><span class='swift_emoticon_text' " + textStyle + ">" + QtUtilities::htmlEscape(P2QSTRING(emoticonPart->alternativeText)) + "</span>";
continue;