diff options
Diffstat (limited to 'SwifTools')
-rw-r--r-- | SwifTools/Application/ApplicationPathProvider.cpp | 3 | ||||
-rw-r--r-- | SwifTools/Application/UnixApplicationPathProvider.cpp | 8 | ||||
-rw-r--r-- | SwifTools/Notifier/GNTPNotifier.cpp | 3 | ||||
-rw-r--r-- | SwifTools/TabComplete.cpp | 4 |
4 files changed, 6 insertions, 12 deletions
diff --git a/SwifTools/Application/ApplicationPathProvider.cpp b/SwifTools/Application/ApplicationPathProvider.cpp index a5080f9..8b952bb 100644 --- a/SwifTools/Application/ApplicationPathProvider.cpp +++ b/SwifTools/Application/ApplicationPathProvider.cpp @@ -1,49 +1,48 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <SwifTools/Application/ApplicationPathProvider.h> #include <boost/filesystem.hpp> #include <Swiften/Base/Log.h> #include <Swiften/Base/Paths.h> -#include <Swiften/Base/foreach.h> namespace Swift { ApplicationPathProvider::ApplicationPathProvider(const std::string& applicationName) : applicationName(applicationName) { } ApplicationPathProvider::~ApplicationPathProvider() { } boost::filesystem::path ApplicationPathProvider::getProfileDir(const std::string& profile) const { boost::filesystem::path result(getHomeDir() / profile); try { boost::filesystem::create_directory(result); } catch (const boost::filesystem::filesystem_error& e) { SWIFT_LOG(error) << e.what() << std::endl; } return result; } boost::filesystem::path ApplicationPathProvider::getResourcePath(const std::string& resource) const { std::vector<boost::filesystem::path> resourcePaths = getResourceDirs(); - foreach(const boost::filesystem::path& resourcePath, resourcePaths) { + for (const auto& resourcePath : resourcePaths) { boost::filesystem::path r(resourcePath / resource); if (boost::filesystem::exists(r)) { return r; } } return boost::filesystem::path(); } boost::filesystem::path ApplicationPathProvider::getExecutableDir() const { return Paths::getExecutablePath(); } } diff --git a/SwifTools/Application/UnixApplicationPathProvider.cpp b/SwifTools/Application/UnixApplicationPathProvider.cpp index c561d72..e455d23 100644 --- a/SwifTools/Application/UnixApplicationPathProvider.cpp +++ b/SwifTools/Application/UnixApplicationPathProvider.cpp @@ -1,64 +1,62 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <SwifTools/Application/UnixApplicationPathProvider.h> #include <stdlib.h> -#include <iostream> - #include <boost/algorithm/string.hpp> #include <unistd.h> +#include <Swiften/Base/Log.h> #include <Swiften/Base/String.h> -#include <Swiften/Base/foreach.h> namespace Swift { UnixApplicationPathProvider::UnixApplicationPathProvider(const std::string& name) : ApplicationPathProvider(name) { resourceDirs.push_back(getExecutableDir() / "../resources"); // Development resourceDirs.push_back(getExecutableDir() / ".." / "share" / boost::to_lower_copy(getApplicationName())); // Local install char* xdgDataDirs = getenv("XDG_DATA_DIRS"); if (xdgDataDirs) { std::vector<std::string> dataDirs = String::split(xdgDataDirs, ':'); if (!dataDirs.empty()) { - foreach(const std::string& dir, dataDirs) { + for (const auto& dir : dataDirs) { resourceDirs.push_back(boost::filesystem::path(dir) / "swift"); } return; } } resourceDirs.push_back("/usr/local/share/" + boost::to_lower_copy(getApplicationName())); resourceDirs.push_back("/usr/share/" + boost::to_lower_copy(getApplicationName())); } boost::filesystem::path UnixApplicationPathProvider::getHomeDir() const { char* home = getenv("HOME"); return home ? boost::filesystem::path(home) : boost::filesystem::path(); } boost::filesystem::path UnixApplicationPathProvider::getDataDir() const { char* xdgDataHome = getenv("XDG_DATA_HOME"); std::string dataDir; if (xdgDataHome) { dataDir = std::string(xdgDataHome); } boost::filesystem::path dataPath = (dataDir.empty() ? getHomeDir() / ".local" / "share" : boost::filesystem::path(dataDir)) / boost::to_lower_copy(getApplicationName()); try { boost::filesystem::create_directories(dataPath); } catch (const boost::filesystem::filesystem_error& e) { - std::cerr << "ERROR: " << e.what() << std::endl; + SWIFT_LOG(error) << "file system error: " << e.what() << std::endl; } return dataPath; } } diff --git a/SwifTools/Notifier/GNTPNotifier.cpp b/SwifTools/Notifier/GNTPNotifier.cpp index 62203b4..89025af 100644 --- a/SwifTools/Notifier/GNTPNotifier.cpp +++ b/SwifTools/Notifier/GNTPNotifier.cpp @@ -1,62 +1,61 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ // FIXME: This notifier needs finishing (handling callbacks etc.) #include <SwifTools/Notifier/GNTPNotifier.h> #include <cassert> #include <iostream> #include <sstream> #include <boost/bind.hpp> #include <Swiften/Base/Path.h> -#include <Swiften/Base/foreach.h> #include <Swiften/Network/ConnectionFactory.h> namespace Swift { GNTPNotifier::GNTPNotifier(const std::string& name, const boost::filesystem::path& icon, ConnectionFactory* connectionFactory) : name(name), icon(icon), connectionFactory(connectionFactory), initialized(false), registered(false) { // Registration message std::ostringstream message; message << "GNTP/1.0 REGISTER NONE\r\n"; message << "Application-Name: " << name << "\r\n"; message << "Application-Icon: file://" << pathToString(icon) << "\r\n"; message << "Notifications-Count: " << getAllTypes().size() << "\r\n"; std::vector<Notifier::Type> defaultTypes = getDefaultTypes(); std::vector<Notifier::Type> allTypes = getAllTypes(); - foreach(Notifier::Type type, allTypes) { + for (const auto& type : allTypes) { message << "\r\n"; message << "Notification-Name: " << typeToString(type) << "\r\n"; message << "Notification-Enabled: " << (std::find(defaultTypes.begin(), defaultTypes.end(), type) == defaultTypes.end() ? "false" : "true") << "\r\n"; } message << "\r\n"; send(message.str()); } GNTPNotifier::~GNTPNotifier() { } void GNTPNotifier::send(const std::string& message) { if (currentConnection) { return; } currentMessage = message; currentConnection = connectionFactory->createConnection(); currentConnection->onConnectFinished.connect(boost::bind(&GNTPNotifier::handleConnectFinished, this, _1)); currentConnection->onDataRead.connect(boost::bind(&GNTPNotifier::handleDataRead, this, _1)); currentConnection->connect(HostAddressPort(HostAddress("127.0.0.1"), 23053)); } void GNTPNotifier::showMessage(Type type, const std::string& subject, const std::string& description, const boost::filesystem::path& picture, boost::function<void()>) { if (registered) { std::ostringstream message; message << "GNTP/1.0 NOTIFY NONE\r\n"; message << "Application-Name: " << name << "\r\n"; message << "Notification-Name: " << typeToString(type) << "\r\n"; message << "Notification-Title: " << subject << "\r\n"; diff --git a/SwifTools/TabComplete.cpp b/SwifTools/TabComplete.cpp index f158ffa..39a70cc 100644 --- a/SwifTools/TabComplete.cpp +++ b/SwifTools/TabComplete.cpp @@ -1,56 +1,54 @@ /* * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #include <SwifTools/TabComplete.h> #include <algorithm> #include <boost/algorithm/string.hpp> -#include <Swiften/Base/foreach.h> - namespace Swift { void TabComplete::addWord(const std::string& word) { words_.erase(std::remove(words_.begin(), words_.end(), word), words_.end()); words_.insert(words_.begin(), word); if (boost::starts_with(boost::to_lower_copy(word), lastShort_)) { lastCompletionCandidates_.insert(lastCompletionCandidates_.begin(), word); } } void TabComplete::removeWord(const std::string& word) { words_.erase(std::remove(words_.begin(), words_.end(), word), words_.end()); lastCompletionCandidates_.erase(std::remove(lastCompletionCandidates_.begin(), lastCompletionCandidates_.end(), word), lastCompletionCandidates_.end()); } std::string TabComplete::completeWord(const std::string& word) { if (word == lastCompletion_) { if (!lastCompletionCandidates_.empty()) { size_t match = 0; for (match = 0; match < lastCompletionCandidates_.size(); match++) { if (lastCompletionCandidates_[match] == lastCompletion_) { break; } } size_t nextIndex = match + 1; nextIndex = nextIndex >= lastCompletionCandidates_.size() ? 0 : nextIndex; lastCompletion_ = lastCompletionCandidates_[nextIndex]; } } else { lastShort_ = boost::to_lower_copy(word); lastCompletionCandidates_.clear(); - foreach (std::string candidate, words_) { + for (auto&& candidate : words_) { if (boost::starts_with(boost::to_lower_copy(candidate), boost::to_lower_copy(word))) { lastCompletionCandidates_.push_back(candidate); } } lastCompletion_ = !lastCompletionCandidates_.empty() ? lastCompletionCandidates_[0] : word; } return lastCompletion_; } } |