summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Markmann <tm@ayena.de>2016-07-29 20:59:54 (GMT)
committerKevin Smith <kevin.smith@isode.com>2016-08-09 20:15:12 (GMT)
commit42defb3516a8b7f06c7b0fbc832332a4e60c0f86 (patch)
treeb833bc3cf0166947da16345be511b71dcb04baca /Swift/Controllers/Roster
parent3c7b2b3dc884f347771f6e3036779193e7e45627 (diff)
downloadswift-42defb3516a8b7f06c7b0fbc832332a4e60c0f86.zip
swift-42defb3516a8b7f06c7b0fbc832332a4e60c0f86.tar.bz2
Enable better date formatting in the UI
This adds the ability to provide more specific date formatting via the Translator interface. The default translator will use Boost's formatting capabilities. The QtTranslator use more localized and better readable formatting. Test-Information: Tested with Qt 5.5.1 on OS X 10.11.6. Checked that tooltips and presence text in new chat views show the new formatting. Change-Id: I90ff5ab8b31fb41f2dcbea2c40b8846c534c355f
Diffstat (limited to 'Swift/Controllers/Roster')
-rw-r--r--Swift/Controllers/Roster/ContactRosterItem.cpp32
-rw-r--r--Swift/Controllers/Roster/ContactRosterItem.h6
2 files changed, 30 insertions, 8 deletions
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_;