diff options
Diffstat (limited to 'Swift/QtUI/QtHistoryWindow.cpp')
| -rw-r--r-- | Swift/QtUI/QtHistoryWindow.cpp | 20 | 
1 files changed, 12 insertions, 8 deletions
diff --git a/Swift/QtUI/QtHistoryWindow.cpp b/Swift/QtUI/QtHistoryWindow.cpp index e54bd51..6f22b76 100644 --- a/Swift/QtUI/QtHistoryWindow.cpp +++ b/Swift/QtUI/QtHistoryWindow.cpp @@ -1,5 +1,5 @@  /* - * Copyright (c) 2012 Catalin Badea + * Copyright (c) 2012-2013 Catalin Badea   * Licensed under the simplified BSD license.   * See Documentation/Licenses/BSD-simplified.txt for more information.   */ @@ -13,6 +13,7 @@  #include <string>  #include <boost/shared_ptr.hpp> +#include <boost/smart_ptr/make_shared.hpp>  #include <QTime>  #include <QUrl> @@ -20,9 +21,12 @@  #include <QTextDocument>  #include <QDateTime>  #include <Swift/QtUI/QtScaledAvatarCache.h> +#include <Swift/QtUI/ChatSnippet.h>  #include <QLineEdit> +#include "QtUtilities.h"  #include <boost/smart_ptr/make_shared.hpp> +#include <boost/numeric/conversion/cast.hpp>  #include <boost/date_time/gregorian/gregorian.hpp>  namespace Swift { @@ -107,7 +111,7 @@ void QtHistoryWindow::addMessage(const std::string &message, const std::string &  	QString scaledAvatarPath = QtScaledAvatarCache(32).getScaledAvatarPath(avatarPath.c_str());  	QString messageHTML(P2QSTRING(message)); -	messageHTML = Qt::escape(messageHTML); +	messageHTML = QtUtilities::htmlEscape(messageHTML);  	QString searchTerm = ui_.searchBox_->lineEdit()->text();  	if (searchTerm.length()) {  		messageHTML.replace(searchTerm, "<span style='background-color: yellow'>" + searchTerm + "</span>"); @@ -124,14 +128,14 @@ void QtHistoryWindow::addMessage(const std::string &message, const std::string &  	if (addAtTheTop) {  		bool appendToPrevious = ((senderIsSelf && previousTopMessageWasSelf_) || (!senderIsSelf && !previousTopMessageWasSelf_&& previousTopSenderName_ == P2QSTRING(senderName))); -		conversation_->addMessageTop(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, Qt::escape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id)))); +		conversation_->addMessageTop(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, QtUtilities::htmlEscape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), ChatSnippet::getDirection(message))));  		previousTopMessageWasSelf_ = senderIsSelf;  		previousTopSenderName_ = P2QSTRING(senderName);  	}  	else {  		bool appendToPrevious = ((senderIsSelf && previousBottomMessageWasSelf_) || (!senderIsSelf && !previousBottomMessageWasSelf_&& previousBottomSenderName_ == P2QSTRING(senderName))); -		conversation_->addMessageBottom(boost::shared_ptr<ChatSnippet>(new MessageSnippet(messageHTML, Qt::escape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id)))); +		conversation_->addMessageBottom(boost::make_shared<MessageSnippet>(messageHTML, QtUtilities::htmlEscape(P2QSTRING(senderName)), qTime, qAvatarPath, senderIsSelf, appendToPrevious, theme_, P2QSTRING(id), ChatSnippet::getDirection(message)));  		previousBottomMessageWasSelf_ = senderIsSelf;  		previousBottomSenderName_ = P2QSTRING(senderName);  	} @@ -183,7 +187,7 @@ void QtHistoryWindow::handleScrollReachedTop() {  	int year, month, day;  	QDate firstDate = *dates_.begin();  	firstDate.getDate(&year, &month, &day); -	onScrollReachedTop(boost::gregorian::date(year, month, day)); +	onScrollReachedTop(boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day)));  }  void QtHistoryWindow::handleScrollReachedBottom() { @@ -194,7 +198,7 @@ void QtHistoryWindow::handleScrollReachedBottom() {  	int year, month, day;  	QDate lastDate = *dates_.rbegin();  	lastDate.getDate(&year, &month, &day); -	onScrollReachedBottom(boost::gregorian::date(year, month, day)); +	onScrollReachedBottom(boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day)));  }  void QtHistoryWindow::handleReturnPressed() { @@ -205,7 +209,7 @@ void QtHistoryWindow::handleCalendarClicked(const QDate& date) {  	int year, month, day;  	QDate tempDate = date; // getDate discards const qualifier  	tempDate.getDate(&year, &month, &day); -	onCalendarClicked(boost::gregorian::date(year, month, day)); +	onCalendarClicked(boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day)));  }  void QtHistoryWindow::setDate(const boost::gregorian::date& date) { @@ -242,7 +246,7 @@ boost::gregorian::date QtHistoryWindow::getLastVisibleDate() {  		int year, month, day;  		lastDate.getDate(&year, &month, &day); -		return boost::gregorian::date(year, month, day); +		return boost::gregorian::date(boost::numeric_cast<unsigned short>(year), boost::numeric_cast<unsigned short>(month), boost::numeric_cast<unsigned short>(day));  	}  	return boost::gregorian::date(boost::gregorian::not_a_date_time);  }  | 
 Swift