diff options
| author | Remko Tronçon <git@el-tramo.be> | 2013-05-15 19:44:37 (GMT) | 
|---|---|---|
| committer | Remko Tronçon <git@el-tramo.be> | 2013-05-17 19:00:55 (GMT) | 
| commit | de39ce6ec44647cee92853e2928cf5475af992e6 (patch) | |
| tree | 1f86dd075900aeeb9b91cdd120d71052458ca6ff /Swift/Controllers/Chat | |
| parent | 927d62cc54c8a5087dba6b61afa9ad30dc528a23 (diff) | |
| download | swift-contrib-de39ce6ec44647cee92853e2928cf5475af992e6.zip swift-contrib-de39ce6ec44647cee92853e2928cf5475af992e6.tar.bz2 | |
Fixed unicode path handling.
- Use boost::filesystem::path consistently for referring to files.
- Use boost::filesystem streams for I/O, such that paths are always handled
  correctly.
- Use stringToPath and pathToString for conversion between strings and
  boost::filesystem::path, to ensure we have consistent unicode handling
  across platforms and environments. The default constructor and string
  conversion uses platform-dependent encoding, depending on the global
  locale set in the application, which causes problems. So, unless you are
  in platform dependent code, the default constructor and string() function
  should not be used. When constructing paths from other paths (e.g. using
  operator/), also use stringToPath (instead of string arguments) if the path
  can contain unicode characters.
Change-Id: If286bd9e71c8414afc0b24ba67e26ab7608ef6ea
Diffstat (limited to 'Swift/Controllers/Chat')
| -rw-r--r-- | Swift/Controllers/Chat/ChatController.cpp | 2 | ||||
| -rw-r--r-- | Swift/Controllers/Chat/ChatControllerBase.cpp | 9 | ||||
| -rw-r--r-- | Swift/Controllers/Chat/ChatControllerBase.h | 4 | ||||
| -rw-r--r-- | Swift/Controllers/Chat/MUCController.cpp | 9 | 
4 files changed, 12 insertions, 12 deletions
| diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp index 1fb45a9..f5c690c 100644 --- a/Swift/Controllers/Chat/ChatController.cpp +++ b/Swift/Controllers/Chat/ChatController.cpp @@ -285,7 +285,7 @@ void ChatController::postSendMessage(const std::string& body, boost::shared_ptr<  		eraseIf(unackedStanzas_, PairSecondEquals<boost::shared_ptr<Stanza>, std::string>(myLastMessageUIID_));  		replaceMessage(body, myLastMessageUIID_, boost::posix_time::microsec_clock::universal_time(), HighlightAction());  	} else { -		myLastMessageUIID_ = addMessage(body, QT_TRANSLATE_NOOP("", "me"), true, labelsEnabled_ ? chatWindow_->getSelectedSecurityLabel().getLabel() : boost::shared_ptr<SecurityLabel>(), std::string(avatarManager_->getAvatarPath(selfJID_).string()), boost::posix_time::microsec_clock::universal_time(), HighlightAction()); +		myLastMessageUIID_ = addMessage(body, QT_TRANSLATE_NOOP("", "me"), true, labelsEnabled_ ? chatWindow_->getSelectedSecurityLabel().getLabel() : boost::shared_ptr<SecurityLabel>(), avatarManager_->getAvatarPath(selfJID_), boost::posix_time::microsec_clock::universal_time(), HighlightAction());  	}  	if (stanzaChannel_->getStreamManagementEnabled() && !myLastMessageUIID_.empty() ) { diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp index e469637..621fd2d 100644 --- a/Swift/Controllers/Chat/ChatControllerBase.cpp +++ b/Swift/Controllers/Chat/ChatControllerBase.cpp @@ -18,6 +18,7 @@  #include <Swift/Controllers/Intl.h>  #include <Swiften/Base/format.h> +#include <Swiften/Base/Path.h>  #include <Swiften/Base/String.h>  #include <Swiften/Client/StanzaChannel.h>  #include <Swiften/Elements/Delay.h> @@ -179,11 +180,11 @@ void ChatControllerBase::activateChatWindow() {  	chatWindow_->activate();  } -std::string ChatControllerBase::addMessage(const std::string& message, const std::string& senderName, bool senderIsSelf, const boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time, const HighlightAction& highlight) { +std::string ChatControllerBase::addMessage(const std::string& message, const std::string& senderName, bool senderIsSelf, const boost::shared_ptr<SecurityLabel> label, const boost::filesystem::path& avatarPath, const boost::posix_time::ptime& time, const HighlightAction& highlight) {  	if (boost::starts_with(message, "/me ")) { -		return chatWindow_->addAction(String::getSplittedAtFirst(message, ' ').second, senderName, senderIsSelf, label, avatarPath, time, highlight); +		return chatWindow_->addAction(String::getSplittedAtFirst(message, ' ').second, senderName, senderIsSelf, label, pathToString(avatarPath), time, highlight);  	} else { -		return chatWindow_->addMessage(message, senderName, senderIsSelf, label, avatarPath, time, highlight); +		return chatWindow_->addMessage(message, senderName, senderIsSelf, label, pathToString(avatarPath), time, highlight);  	}  } @@ -266,7 +267,7 @@ void ChatControllerBase::handleIncomingMessage(boost::shared_ptr<MessageEvent> m  			}  		}  		else { -			lastMessagesUIID_[from] = addMessage(body, senderDisplayNameFromMessage(from), isIncomingMessageFromMe(message), label, std::string(avatarManager_->getAvatarPath(from).string()), timeStamp, highlight); +			lastMessagesUIID_[from] = addMessage(body, senderDisplayNameFromMessage(from), isIncomingMessageFromMe(message), label, avatarManager_->getAvatarPath(from), timeStamp, highlight);  		}  		logMessage(body, from, selfJID_, timeStamp, true); diff --git a/Swift/Controllers/Chat/ChatControllerBase.h b/Swift/Controllers/Chat/ChatControllerBase.h index 84bd06a..0199142 100644 --- a/Swift/Controllers/Chat/ChatControllerBase.h +++ b/Swift/Controllers/Chat/ChatControllerBase.h @@ -10,7 +10,7 @@  #include <vector>  #include <boost/shared_ptr.hpp>  #include "Swiften/Base/boost_bsignals.h" -#include <boost/filesystem.hpp> +#include <boost/filesystem/path.hpp>  #include <boost/optional.hpp>  #include <boost/date_time/posix_time/posix_time.hpp> @@ -50,7 +50,7 @@ namespace Swift {  			void activateChatWindow();  			virtual void setAvailableServerFeatures(boost::shared_ptr<DiscoInfo> info);  			void handleIncomingMessage(boost::shared_ptr<MessageEvent> message); -			std::string addMessage(const std::string& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const std::string& avatarPath, const boost::posix_time::ptime& time, const HighlightAction& highlight); +			std::string addMessage(const std::string& message, const std::string& senderName, bool senderIsSelf, boost::shared_ptr<SecurityLabel> label, const boost::filesystem::path& avatarPath, const boost::posix_time::ptime& time, const HighlightAction& highlight);  			void replaceMessage(const std::string& message, const std::string& id, const boost::posix_time::ptime& time, const HighlightAction& highlight);  			virtual void setOnline(bool online);  			virtual void setEnabled(bool enabled); diff --git a/Swift/Controllers/Chat/MUCController.cpp b/Swift/Controllers/Chat/MUCController.cpp index b964bad..6bf3e5f 100644 --- a/Swift/Controllers/Chat/MUCController.cpp +++ b/Swift/Controllers/Chat/MUCController.cpp @@ -312,8 +312,7 @@ void MUCController::handleAvatarChanged(const JID& jid) {  	if (parting_ || !jid.equals(toJID_, JID::WithoutResource)) {  		return;  	} -	std::string path = avatarManager_->getAvatarPath(jid).string(); -	roster_->applyOnItems(SetAvatar(jid, path, JID::WithResource)); +	roster_->applyOnItems(SetAvatar(jid, avatarManager_->getAvatarPath(jid), JID::WithResource));  }  void MUCController::handleWindowClosed() { @@ -337,7 +336,7 @@ void MUCController::handleOccupantJoined(const MUCOccupant& occupant) {  	NickJoinPart event(occupant.getNick(), Join);  	appendToJoinParts(joinParts_, event);  	std::string groupName(roleToGroupName(occupant.getRole())); -	roster_->addContact(jid, realJID, occupant.getNick(), groupName, avatarManager_->getAvatarPath(jid).string()); +	roster_->addContact(jid, realJID, occupant.getNick(), groupName, avatarManager_->getAvatarPath(jid));  	roster_->getGroup(groupName)->setManualSort(roleToSortName(occupant.getRole()));  	if (joined_) {  		std::string joinString; @@ -483,7 +482,7 @@ void MUCController::handleOccupantRoleChanged(const std::string& nick, const MUC  		realJID = occupant.getRealJID().get();  	}  	std::string group(roleToGroupName(occupant.getRole())); -	roster_->addContact(jid, realJID, nick, group, avatarManager_->getAvatarPath(jid).string()); +	roster_->addContact(jid, realJID, nick, group, avatarManager_->getAvatarPath(jid));  	roster_->getGroup(group)->setManualSort(roleToSortName(occupant.getRole()));  	chatWindow_->addSystemMessage(str(format(QT_TRANSLATE_NOOP("", "%1% is now a %2%")) % nick % roleToFriendlyName(occupant.getRole())), ChatWindow::DefaultDirection);  	if (nick == nick_) { @@ -830,7 +829,7 @@ void MUCController::addRecentLogs() {  		bool senderIsSelf = nick_ == message.getFromJID().getResource();  		// the chatWindow uses utc timestamps -		addMessage(message.getMessage(), senderDisplayNameFromMessage(message.getFromJID()), senderIsSelf, boost::shared_ptr<SecurityLabel>(new SecurityLabel()), std::string(avatarManager_->getAvatarPath(message.getFromJID()).string()), message.getTime() - boost::posix_time::hours(message.getOffset()), HighlightAction()); +		addMessage(message.getMessage(), senderDisplayNameFromMessage(message.getFromJID()), senderIsSelf, boost::shared_ptr<SecurityLabel>(new SecurityLabel()), avatarManager_->getAvatarPath(message.getFromJID()), message.getTime() - boost::posix_time::hours(message.getOffset()), HighlightAction());  	}  } | 
 Swift
 Swift