summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2013-05-15 19:44:37 (GMT)
committerRemko Tronçon <git@el-tramo.be>2013-05-17 19:00:55 (GMT)
commitde39ce6ec44647cee92853e2928cf5475af992e6 (patch)
tree1f86dd075900aeeb9b91cdd120d71052458ca6ff /Swift/QtUI
parent927d62cc54c8a5087dba6b61afa9ad30dc528a23 (diff)
downloadswift-de39ce6ec44647cee92853e2928cf5475af992e6.zip
swift-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/QtUI')
-rw-r--r--Swift/QtUI/ChatList/ChatListRecentItem.cpp5
-rw-r--r--Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp9
-rw-r--r--Swift/QtUI/FreeDesktopNotifier.cpp5
-rw-r--r--Swift/QtUI/QtCachedImageScaler.cpp13
-rw-r--r--Swift/QtUI/QtSoundPlayer.cpp10
-rw-r--r--Swift/QtUI/QtSwift.cpp7
-rw-r--r--Swift/QtUI/Roster/RosterModel.cpp5
-rw-r--r--Swift/QtUI/main.cpp7
8 files changed, 39 insertions, 22 deletions
diff --git a/Swift/QtUI/ChatList/ChatListRecentItem.cpp b/Swift/QtUI/ChatList/ChatListRecentItem.cpp
index 6c9807f..5a4d1e1 100644
--- a/Swift/QtUI/ChatList/ChatListRecentItem.cpp
+++ b/Swift/QtUI/ChatList/ChatListRecentItem.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011 Kevin Smith
+ * Copyright (c) 2011-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -7,6 +7,7 @@
#include <Swift/QtUI/ChatList/ChatListRecentItem.h>
#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swiften/Base/Path.h>
namespace Swift {
ChatListRecentItem::ChatListRecentItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent) : ChatListItem(parent), chat_(chat) {
@@ -25,7 +26,7 @@ QVariant ChatListRecentItem::data(int role) const {
case Qt::BackgroundColorRole: return backgroundColor_;
case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant();
case StatusTextRole: return statusText_;*/
- case AvatarRole: return QVariant(QString(chat_.avatarPath.string().c_str()));
+ case AvatarRole: return QVariant(P2QSTRING(pathToString(chat_.avatarPath)));
case PresenceIconRole: return getPresenceIcon();
default: return QVariant();
}
diff --git a/Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp b/Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp
index 41648b6..6791aa5 100644
--- a/Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp
+++ b/Swift/QtUI/ChatList/ChatListWhiteboardItem.cpp
@@ -4,9 +4,16 @@
* See Documentation/Licenses/BSD-simplified.txt for more information.
*/
+/*
+ * Copyright (c) 2013 Remko Tronçon
+ * Licensed under the GNU General Public License.
+ * See the COPYING file for more information.
+ */
+
#include <Swift/QtUI/ChatList/ChatListWhiteboardItem.h>
#include <Swift/QtUI/QtSwiftUtil.h>
+#include <Swiften/Base/Path.h>
namespace Swift {
ChatListWhiteboardItem::ChatListWhiteboardItem(const ChatListWindow::Chat& chat, ChatListGroupItem* parent) : ChatListItem(parent), chat_(chat) {
@@ -25,7 +32,7 @@ namespace Swift {
case Qt::BackgroundColorRole: return backgroundColor_;
case Qt::ToolTipRole: return isContact() ? toolTipString() : QVariant();
case StatusTextRole: return statusText_;*/
- case AvatarRole: return QVariant(QString(chat_.avatarPath.string().c_str()));
+ case AvatarRole: return QVariant(P2QSTRING(pathToString(chat_.avatarPath)));
case PresenceIconRole: return getPresenceIcon();
default: return QVariant();
}
diff --git a/Swift/QtUI/FreeDesktopNotifier.cpp b/Swift/QtUI/FreeDesktopNotifier.cpp
index 2393340..a51e482 100644
--- a/Swift/QtUI/FreeDesktopNotifier.cpp
+++ b/Swift/QtUI/FreeDesktopNotifier.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -13,6 +13,7 @@
#include <QStringList>
#include <QtDBus/QtDBus>
#include <algorithm>
+#include <Swiften/Base/Path.h>
namespace Swift {
@@ -43,7 +44,7 @@ void FreeDesktopNotifier::showMessage(Type type, const std::string& subject, con
hints["x-canonical-append"] = QString("allowed");
msg << applicationName.c_str();
msg << quint32(0); // ID of previous notification to replace
- msg << imageScaler.getScaledImage(picture, 48).string().c_str(); // Icon to display
+ msg << pathToString(imageScaler.getScaledImage(picture, 48)); // Icon to display
msg << subject.c_str(); // Summary / Header of the message to display
msg << body; // Body of the message to display
msg << actions; // Actions from which the user may choose
diff --git a/Swift/QtUI/QtCachedImageScaler.cpp b/Swift/QtUI/QtCachedImageScaler.cpp
index 7307577..9b1709b 100644
--- a/Swift/QtUI/QtCachedImageScaler.cpp
+++ b/Swift/QtUI/QtCachedImageScaler.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Remko Tronçon
+ * Copyright (c) 2010-2013 Remko Tronçon
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -8,6 +8,8 @@
#include <QImage>
#include <boost/lexical_cast.hpp>
+#include <Swiften/Base/Path.h>
+#include <Swift/QtUI/QtSwiftUtil.h>
namespace Swift {
@@ -15,16 +17,17 @@ QtCachedImageScaler::QtCachedImageScaler() {
}
boost::filesystem::path QtCachedImageScaler::getScaledImage(const boost::filesystem::path& imagePath, int size) {
- boost::filesystem::path scaledImagePath(imagePath.string() + "." + boost::lexical_cast<std::string>(size));
+ boost::filesystem::path scaledImagePath(imagePath);
+ scaledImagePath += "." + boost::lexical_cast<std::string>(size);
if (!boost::filesystem::exists(scaledImagePath)) {
- QImage image(imagePath.string().c_str());
+ QImage image(P2QSTRING(pathToString(imagePath)));
if (!image.isNull()) {
if (image.width() > size || image.height() > size) {
QImage scaledImage = image.scaled(size, size, Qt::KeepAspectRatio, Qt::SmoothTransformation);
- scaledImage.save(QString::fromUtf8(scaledImagePath.string().c_str()), "PNG");
+ scaledImage.save(P2QSTRING(pathToString(scaledImagePath)), "PNG");
}
else {
- image.save(QString::fromUtf8(scaledImagePath.string().c_str()), "PNG");
+ image.save(P2QSTRING(pathToString(scaledImagePath)), "PNG");
}
}
else {
diff --git a/Swift/QtUI/QtSoundPlayer.cpp b/Swift/QtUI/QtSoundPlayer.cpp
index 63f76f0..3f3782d 100644
--- a/Swift/QtUI/QtSoundPlayer.cpp
+++ b/Swift/QtUI/QtSoundPlayer.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -9,7 +9,9 @@
#include <QSound>
#include <iostream>
-#include "SwifTools/Application/ApplicationPathProvider.h"
+#include <SwifTools/Application/ApplicationPathProvider.h>
+#include <QtSwiftUtil.h>
+#include <Swiften/Base/Path.h>
namespace Swift {
@@ -28,10 +30,10 @@ void QtSoundPlayer::playSound(SoundEffect sound, const std::string& soundResourc
void QtSoundPlayer::playSound(const std::string& soundResource) {
boost::filesystem::path resourcePath = applicationPathProvider->getResourcePath(soundResource);
if (boost::filesystem::exists(resourcePath)) {
- QSound::play(resourcePath.string().c_str());
+ QSound::play(P2QSTRING(pathToString(resourcePath)));
}
else if (boost::filesystem::exists(soundResource)) {
- QSound::play(soundResource.c_str());
+ QSound::play(P2QSTRING(soundResource));
}
else {
std::cerr << "Unable to find sound: " << soundResource << std::endl;
diff --git a/Swift/QtUI/QtSwift.cpp b/Swift/QtUI/QtSwift.cpp
index 839d079..b563c53 100644
--- a/Swift/QtUI/QtSwift.cpp
+++ b/Swift/QtUI/QtSwift.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010-2012 Kevin Smith
+ * Copyright (c) 2010-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -23,6 +23,7 @@
#include <QtChatWindowFactory.h>
#include <QtSingleWindow.h>
#include <Swiften/Base/Log.h>
+#include <Swiften/Base/Path.h>
#include <Swift/Controllers/Storages/CertificateFileStorageFactory.h>
#include <Swift/Controllers/Storages/FileStoragesFactory.h>
#include <SwifTools/Application/PlatformApplicationPathProvider.h>
@@ -129,14 +130,14 @@ QtSwift::QtSwift(const po::variables_map& options) : networkFactories_(&clientMa
QCoreApplication::setApplicationVersion(buildVersion);
qtSettings_ = new QtSettingsProvider();
- xmlSettings_ = loadSettingsFile(P2QSTRING((Paths::getExecutablePath() / "system-settings.xml").string()));
+ xmlSettings_ = loadSettingsFile(P2QSTRING(pathToString(Paths::getExecutablePath() / "system-settings.xml")));
settingsHierachy_ = new SettingsProviderHierachy();
settingsHierachy_->addProviderToTopOfStack(xmlSettings_);
settingsHierachy_->addProviderToTopOfStack(qtSettings_);
QMap<QString, QString> emoticons;
loadEmoticonsFile(":/emoticons/emoticons.txt", emoticons);
- loadEmoticonsFile(P2QSTRING((Paths::getExecutablePath() / "emoticons.txt").string()), emoticons);
+ loadEmoticonsFile(P2QSTRING(pathToString(Paths::getExecutablePath() / "emoticons.txt")), emoticons);
if (options.count("netbook-mode")) {
splitter_ = new QtSingleWindow(qtSettings_);
diff --git a/Swift/QtUI/Roster/RosterModel.cpp b/Swift/QtUI/Roster/RosterModel.cpp
index 8f39f35..1b93047 100644
--- a/Swift/QtUI/Roster/RosterModel.cpp
+++ b/Swift/QtUI/Roster/RosterModel.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2010 Kevin Smith
+ * Copyright (c) 2010-2013 Kevin Smith
* Licensed under the GNU General Public License v3.
* See Documentation/Licenses/GPLv3.txt for more information.
*/
@@ -16,6 +16,7 @@
#include "Swift/Controllers/Roster/ContactRosterItem.h"
#include "Swift/Controllers/Roster/GroupRosterItem.h"
#include <Swift/Controllers/StatusUtil.h>
+#include <Swiften/Base/Path.h>
#include "QtSwiftUtil.h"
#include "Swift/QtUI/Roster/QtTreeWidget.h"
@@ -150,7 +151,7 @@ QString RosterModel::getAvatar(RosterItem* item) const {
if (!contact) {
return "";
}
- return QString(contact->getAvatarPath().c_str());
+ return P2QSTRING(pathToString(contact->getAvatarPath()));
}
QString RosterModel::getStatusText(RosterItem* item) const {
diff --git a/Swift/QtUI/main.cpp b/Swift/QtUI/main.cpp
index 70947f5..d734713 100644
--- a/Swift/QtUI/main.cpp
+++ b/Swift/QtUI/main.cpp
@@ -21,6 +21,7 @@
#include <SwifTools/Application/PlatformApplicationPathProvider.h>
#include <SwifTools/CrashReporter.h>
#include <stdlib.h>
+#include <Swiften/Base/Path.h>
#include "QtSwift.h"
#include "QtTranslator.h"
@@ -73,14 +74,14 @@ int main(int argc, char* argv[]) {
if (!someTranslationPath.empty()) {
#if QT_VERSION >= 0x040800
if (vm.count("language") > 0) {
- qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + P2QSTRING(vm["language"].as<std::string>()), someTranslationPath.parent_path().string().c_str());
+ qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + P2QSTRING(vm["language"].as<std::string>()), P2QSTRING(Swift::pathToString(someTranslationPath.parent_path())));
}
else {
- qtTranslator.load(QLocale::system(), QString(SWIFT_APPLICATION_NAME).toLower(), "_", someTranslationPath.parent_path().string().c_str());
+ qtTranslator.load(QLocale::system(), QString(SWIFT_APPLICATION_NAME).toLower(), "_", P2QSTRING(Swift::pathToString(someTranslationPath)));
}
#else
//std::cout << "Loading " << std::string(QLocale::system().name().toUtf8()) << std::endl;
- qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + QLocale::system().name(), someTranslationPath.parent_path().string().c_str());
+ qtTranslator.load(QString(SWIFT_APPLICATION_NAME).toLower() + "_" + QLocale::system().name(), P2QSTRING(Swift::pathToString(someTranslationPath)));
#endif
}
app.installTranslator(&qtTranslator);