diff options
Diffstat (limited to 'Swift/Controllers')
-rw-r--r-- | Swift/Controllers/Chat/ChatController.cpp | 6 | ||||
-rw-r--r-- | Swift/Controllers/Chat/ChatControllerBase.cpp | 1 | ||||
-rw-r--r-- | Swift/Controllers/Roster/ContactRosterItem.cpp | 32 | ||||
-rw-r--r-- | Swift/Controllers/Roster/ContactRosterItem.h | 6 | ||||
-rw-r--r-- | Swift/Controllers/Translator.cpp | 8 | ||||
-rw-r--r-- | Swift/Controllers/Translator.h | 6 |
6 files changed, 45 insertions, 14 deletions
diff --git a/Swift/Controllers/Chat/ChatController.cpp b/Swift/Controllers/Chat/ChatController.cpp index e36728a..41a34b9 100644 --- a/Swift/Controllers/Chat/ChatController.cpp +++ b/Swift/Controllers/Chat/ChatController.cpp @@ -12,7 +12,6 @@ #include <Swiften/Avatars/AvatarManager.h> #include <Swiften/Base/Algorithm.h> -#include <Swiften/Base/DateTime.h> #include <Swiften/Base/Log.h> #include <Swiften/Base/format.h> #include <Swiften/Chat/ChatStateNotifier.h> @@ -33,6 +32,7 @@ #include <Swift/Controllers/Intl.h> #include <Swift/Controllers/SettingConstants.h> #include <Swift/Controllers/StatusUtil.h> +#include <Swift/Controllers/Translator.h> #include <Swift/Controllers/UIEvents/AcceptWhiteboardSessionUIEvent.h> #include <Swift/Controllers/UIEvents/CancelWhiteboardSessionUIEvent.h> #include <Swift/Controllers/UIEvents/InviteToMUCUIEvent.h> @@ -74,7 +74,7 @@ ChatController::ChatController(const JID& self, StanzaChannel* stanzaChannel, IQ } Idle::ref idle; if (theirPresence && (idle = theirPresence->getPayload<Idle>())) { - startMessage += str(format(QT_TRANSLATE_NOOP("", ", who has been idle since %1%")) % dateTimeToLocalString(idle->getSince())); + startMessage += str(format(QT_TRANSLATE_NOOP("", ", who has been idle since %1%")) % Swift::Translator::getInstance()->ptimeToHumanReadableString(idle->getSince())); } startMessage += ": " + statusShowTypeToFriendlyName(theirPresence ? theirPresence->getShow() : StatusShow::None); if (theirPresence && !theirPresence->getStatus().empty()) { @@ -466,7 +466,7 @@ std::string ChatController::getStatusChangeString(std::shared_ptr<Presence> pres } Idle::ref idle; if ((idle = presence->getPayload<Idle>())) { - response += str(format(QT_TRANSLATE_NOOP("", " and has been idle since %1%")) % dateTimeToLocalString(idle->getSince())); + response += str(format(QT_TRANSLATE_NOOP("", " and has been idle since %1%")) % Swift::Translator::getInstance()->ptimeToHumanReadableString(idle->getSince())); } if (!response.empty()) { diff --git a/Swift/Controllers/Chat/ChatControllerBase.cpp b/Swift/Controllers/Chat/ChatControllerBase.cpp index a54c89e..b339bd0 100644 --- a/Swift/Controllers/Chat/ChatControllerBase.cpp +++ b/Swift/Controllers/Chat/ChatControllerBase.cpp @@ -12,7 +12,6 @@ #include <boost/algorithm/string.hpp> #include <boost/bind.hpp> -#include <boost/date_time/posix_time/posix_time.hpp> #include <boost/numeric/conversion/cast.hpp> #include <Swiften/Avatars/AvatarManager.h> diff --git a/Swift/Controllers/Roster/ContactRosterItem.cpp b/Swift/Controllers/Roster/ContactRosterItem.cpp index 0ad023a..71c5f8e 100644 --- a/Swift/Controllers/Roster/ContactRosterItem.cpp +++ b/Swift/Controllers/Roster/ContactRosterItem.cpp @@ -11,6 +11,7 @@ #include <Swiften/Base/DateTime.h> #include <Swiften/Base/foreach.h> #include <Swiften/Elements/Idle.h> +#include <Swiften/Elements/Presence.h> #include <Swift/Controllers/Intl.h> #include <Swift/Controllers/Roster/GroupRosterItem.h> @@ -34,7 +35,7 @@ StatusShow::Type ContactRosterItem::getSimplifiedStatusShow() const { switch (presence_ ? presence_->getShow() : StatusShow::None) { case StatusShow::Online: return StatusShow::Online; case StatusShow::Away: return StatusShow::Away; - case StatusShow::XA: return StatusShow::Away; + case StatusShow::XA: return StatusShow::Away; case StatusShow::FFC: return StatusShow::Online; case StatusShow::DND: return StatusShow::DND; case StatusShow::None: return StatusShow::None; @@ -48,22 +49,41 @@ std::string ContactRosterItem::getStatusText() const { } std::string ContactRosterItem::getIdleText() const { - Idle::ref idle = presence_ ? presence_->getPayload<Idle>() : Idle::ref(); - if (!idle || idle->getSince().is_not_a_date_time()) { + boost::posix_time::ptime idleTime = getIdle(); + if (idleTime.is_not_a_date_time()) { return ""; } else { - return dateTimeToLocalString(idle->getSince()); + return dateTimeToLocalString(idleTime); + } +} + +boost::posix_time::ptime ContactRosterItem::getIdle() const { + Idle::ref idle = presence_ ? presence_->getPayload<Idle>() : Idle::ref(); + if (idle) { + return idle->getSince(); + } + else { + return boost::posix_time::not_a_date_time; } } std::string ContactRosterItem::getOfflineSinceText() const { + boost::posix_time::ptime offlineSince = getOfflineSince(); + if (!offlineSince.is_not_a_date_time()) { + return dateTimeToLocalString(offlineSince); + } + return ""; +} + +boost::posix_time::ptime ContactRosterItem::getOfflineSince() const { + boost::posix_time::ptime offlineSince = boost::posix_time::not_a_date_time; if (presence_ && presence_->getType() == Presence::Unavailable) { boost::optional<boost::posix_time::ptime> delay = presence_->getTimestamp(); if (delay) { - return dateTimeToLocalString(*delay); + offlineSince = delay.get(); } } - return ""; + return offlineSince; } void ContactRosterItem::setAvatarPath(const boost::filesystem::path& path) { diff --git a/Swift/Controllers/Roster/ContactRosterItem.h b/Swift/Controllers/Roster/ContactRosterItem.h index 2ffec09..37c3840 100644 --- a/Swift/Controllers/Roster/ContactRosterItem.h +++ b/Swift/Controllers/Roster/ContactRosterItem.h @@ -17,7 +17,6 @@ #include <boost/signals2.hpp> #include <Swiften/Elements/MUCOccupant.h> -#include <Swiften/Elements/Presence.h> #include <Swiften/Elements/StatusShow.h> #include <Swiften/Elements/VCard.h> #include <Swiften/JID/JID.h> @@ -27,6 +26,8 @@ namespace Swift { class GroupRosterItem; +class Presence; + class ContactRosterItem : public RosterItem { public: enum Feature { @@ -49,7 +50,9 @@ class ContactRosterItem : public RosterItem { StatusShow::Type getSimplifiedStatusShow() const; std::string getStatusText() const; std::string getIdleText() const; + boost::posix_time::ptime getIdle() const; std::string getOfflineSinceText() const; + boost::posix_time::ptime getOfflineSince() const; void setAvatarPath(const boost::filesystem::path& path); const boost::filesystem::path& getAvatarPath() const; const JID& getJID() const; @@ -82,7 +85,6 @@ class ContactRosterItem : public RosterItem { private: JID jid_; JID displayJID_; - boost::posix_time::ptime lastAvailableTime_; boost::filesystem::path avatarPath_; std::shared_ptr<Presence> presence_; std::vector<std::string> groups_; diff --git a/Swift/Controllers/Translator.cpp b/Swift/Controllers/Translator.cpp index b62fd28..f03c533 100644 --- a/Swift/Controllers/Translator.cpp +++ b/Swift/Controllers/Translator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -8,12 +8,18 @@ #include <cassert> +#include <Swiften/Base/DateTime.h> + namespace Swift { static struct DefaultTranslator : public Translator { virtual std::string translate(const std::string& text, const std::string&) { return text; } + + virtual std::string ptimeToHumanReadableString(const boost::posix_time::ptime& time) { + return dateTimeToLocalString(time); + } } defaultTranslator; Translator* Translator::translator = &defaultTranslator; diff --git a/Swift/Controllers/Translator.h b/Swift/Controllers/Translator.h index 5c52e9f..f37e059 100644 --- a/Swift/Controllers/Translator.h +++ b/Swift/Controllers/Translator.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 Isode Limited. + * Copyright (c) 2011-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -8,6 +8,8 @@ #include <string> +#include <boost/date_time/posix_time/posix_time_types.hpp> + namespace Swift { class Translator { public: @@ -15,6 +17,8 @@ namespace Swift { virtual std::string translate(const std::string& text, const std::string& context) = 0; + virtual std::string ptimeToHumanReadableString(const boost::posix_time::ptime& time) = 0; + static void setInstance(Translator* translator); static Translator* getInstance() { |