OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #ifndef THIRD_PARTY_LIBJINGLE_FILES_WEBRTC_LIBJINGLE_XMPP_PRESENCESTATUS_H_ |
| 12 #define THIRD_PARTY_LIBJINGLE_FILES_WEBRTC_LIBJINGLE_XMPP_PRESENCESTATUS_H_ |
| 13 |
| 14 #include "webrtc/libjingle/xmpp/constants.h" |
| 15 #include "webrtc/libjingle/xmpp/jid.h" |
| 16 |
| 17 namespace buzz { |
| 18 |
| 19 class PresenceStatus { |
| 20 public: |
| 21 PresenceStatus(); |
| 22 ~PresenceStatus() {} |
| 23 |
| 24 // These are arranged in "priority order", i.e., if we see |
| 25 // two statuses at the same priority but with different Shows, |
| 26 // we will show the one with the highest show in the following |
| 27 // order. |
| 28 enum Show { |
| 29 SHOW_NONE = 0, |
| 30 SHOW_OFFLINE = 1, |
| 31 SHOW_XA = 2, |
| 32 SHOW_AWAY = 3, |
| 33 SHOW_DND = 4, |
| 34 SHOW_ONLINE = 5, |
| 35 SHOW_CHAT = 6, |
| 36 }; |
| 37 |
| 38 const Jid& jid() const { return jid_; } |
| 39 int priority() const { return pri_; } |
| 40 Show show() const { return show_; } |
| 41 const std::string& status() const { return status_; } |
| 42 const std::string& nick() const { return nick_; } |
| 43 bool available() const { return available_ ; } |
| 44 int error_code() const { return e_code_; } |
| 45 const std::string& error_string() const { return e_str_; } |
| 46 bool know_capabilities() const { return know_capabilities_; } |
| 47 bool voice_capability() const { return voice_capability_; } |
| 48 bool pmuc_capability() const { return pmuc_capability_; } |
| 49 bool video_capability() const { return video_capability_; } |
| 50 bool camera_capability() const { return camera_capability_; } |
| 51 const std::string& caps_node() const { return caps_node_; } |
| 52 const std::string& version() const { return version_; } |
| 53 bool feedback_probation() const { return feedback_probation_; } |
| 54 const std::string& sent_time() const { return sent_time_; } |
| 55 |
| 56 void set_jid(const Jid& jid) { jid_ = jid; } |
| 57 void set_priority(int pri) { pri_ = pri; } |
| 58 void set_show(Show show) { show_ = show; } |
| 59 void set_status(const std::string& status) { status_ = status; } |
| 60 void set_nick(const std::string& nick) { nick_ = nick; } |
| 61 void set_available(bool a) { available_ = a; } |
| 62 void set_error(int e_code, const std::string e_str) |
| 63 { e_code_ = e_code; e_str_ = e_str; } |
| 64 void set_know_capabilities(bool f) { know_capabilities_ = f; } |
| 65 void set_voice_capability(bool f) { voice_capability_ = f; } |
| 66 void set_pmuc_capability(bool f) { pmuc_capability_ = f; } |
| 67 void set_video_capability(bool f) { video_capability_ = f; } |
| 68 void set_camera_capability(bool f) { camera_capability_ = f; } |
| 69 void set_caps_node(const std::string& f) { caps_node_ = f; } |
| 70 void set_version(const std::string& v) { version_ = v; } |
| 71 void set_feedback_probation(bool f) { feedback_probation_ = f; } |
| 72 void set_sent_time(const std::string& time) { sent_time_ = time; } |
| 73 |
| 74 void UpdateWith(const PresenceStatus& new_value); |
| 75 |
| 76 bool HasQuietStatus() const { |
| 77 if (status_.empty()) |
| 78 return false; |
| 79 return !(QuietStatus().empty()); |
| 80 } |
| 81 |
| 82 // Knowledge of other clients' silly automatic status strings - |
| 83 // Don't show these. |
| 84 std::string QuietStatus() const { |
| 85 if (jid_.resource().find("Psi") != std::string::npos) { |
| 86 if (status_ == "Online" || |
| 87 status_.find("Auto Status") != std::string::npos) |
| 88 return STR_EMPTY; |
| 89 } |
| 90 if (jid_.resource().find("Gaim") != std::string::npos) { |
| 91 if (status_ == "Sorry, I ran out for a bit!") |
| 92 return STR_EMPTY; |
| 93 } |
| 94 return TrimStatus(status_); |
| 95 } |
| 96 |
| 97 std::string ExplicitStatus() const { |
| 98 std::string result = QuietStatus(); |
| 99 if (result.empty()) { |
| 100 result = ShowStatus(); |
| 101 } |
| 102 return result; |
| 103 } |
| 104 |
| 105 std::string ShowStatus() const { |
| 106 std::string result; |
| 107 if (!available()) { |
| 108 result = "Offline"; |
| 109 } |
| 110 else { |
| 111 switch (show()) { |
| 112 case SHOW_AWAY: |
| 113 case SHOW_XA: |
| 114 result = "Idle"; |
| 115 break; |
| 116 case SHOW_DND: |
| 117 result = "Busy"; |
| 118 break; |
| 119 case SHOW_CHAT: |
| 120 result = "Chatty"; |
| 121 break; |
| 122 default: |
| 123 result = "Available"; |
| 124 break; |
| 125 } |
| 126 } |
| 127 return result; |
| 128 } |
| 129 |
| 130 static std::string TrimStatus(const std::string& st) { |
| 131 std::string s(st); |
| 132 int j = 0; |
| 133 bool collapsing = true; |
| 134 for (unsigned int i = 0; i < s.length(); i+= 1) { |
| 135 if (s[i] <= ' ' && s[i] >= 0) { |
| 136 if (collapsing) { |
| 137 continue; |
| 138 } |
| 139 else { |
| 140 s[j] = ' '; |
| 141 j += 1; |
| 142 collapsing = true; |
| 143 } |
| 144 } |
| 145 else { |
| 146 s[j] = s[i]; |
| 147 j += 1; |
| 148 collapsing = false; |
| 149 } |
| 150 } |
| 151 if (collapsing && j > 0) { |
| 152 j -= 1; |
| 153 } |
| 154 s.erase(j, s.length()); |
| 155 return s; |
| 156 } |
| 157 |
| 158 private: |
| 159 Jid jid_; |
| 160 int pri_; |
| 161 Show show_; |
| 162 std::string status_; |
| 163 std::string nick_; |
| 164 bool available_; |
| 165 int e_code_; |
| 166 std::string e_str_; |
| 167 bool feedback_probation_; |
| 168 |
| 169 // capabilities (valid only if know_capabilities_ |
| 170 bool know_capabilities_; |
| 171 bool voice_capability_; |
| 172 bool pmuc_capability_; |
| 173 bool video_capability_; |
| 174 bool camera_capability_; |
| 175 std::string caps_node_; |
| 176 std::string version_; |
| 177 |
| 178 std::string sent_time_; // from the jabber:x:delay element |
| 179 }; |
| 180 |
| 181 class MucPresenceStatus : public PresenceStatus { |
| 182 }; |
| 183 |
| 184 } // namespace buzz |
| 185 |
| 186 |
| 187 #endif // THIRD_PARTY_LIBJINGLE_FILES_WEBRTC_LIBJINGLE_XMPP_PRESENCESTATUS_H_ |
| 188 |
OLD | NEW |