3 * Copyright 2004--2005, Google Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #ifndef THIRD_PARTY_LIBJINGLE_FILES_TALK_XMPP_PRESENCESTATUS_H_
29 #define THIRD_PARTY_LIBJINGLE_FILES_TALK_XMPP_PRESENCESTATUS_H_
31 #include "talk/xmpp/jid.h"
32 #include "talk/xmpp/constants.h"
36 class PresenceStatus {
41 // These are arranged in "priority order", i.e., if we see
42 // two statuses at the same priority but with different Shows,
43 // we will show the one with the highest show in the following
55 const Jid& jid() const { return jid_; }
56 int priority() const { return pri_; }
57 Show show() const { return show_; }
58 const std::string& status() const { return status_; }
59 const std::string& nick() const { return nick_; }
60 bool available() const { return available_ ; }
61 int error_code() const { return e_code_; }
62 const std::string& error_string() const { return e_str_; }
63 bool know_capabilities() const { return know_capabilities_; }
64 bool voice_capability() const { return voice_capability_; }
65 bool pmuc_capability() const { return pmuc_capability_; }
66 bool video_capability() const { return video_capability_; }
67 bool camera_capability() const { return camera_capability_; }
68 const std::string& caps_node() const { return caps_node_; }
69 const std::string& version() const { return version_; }
70 bool feedback_probation() const { return feedback_probation_; }
71 const std::string& sent_time() const { return sent_time_; }
73 void set_jid(const Jid& jid) { jid_ = jid; }
74 void set_priority(int pri) { pri_ = pri; }
75 void set_show(Show show) { show_ = show; }
76 void set_status(const std::string& status) { status_ = status; }
77 void set_nick(const std::string& nick) { nick_ = nick; }
78 void set_available(bool a) { available_ = a; }
79 void set_error(int e_code, const std::string e_str)
80 { e_code_ = e_code; e_str_ = e_str; }
81 void set_know_capabilities(bool f) { know_capabilities_ = f; }
82 void set_voice_capability(bool f) { voice_capability_ = f; }
83 void set_pmuc_capability(bool f) { pmuc_capability_ = f; }
84 void set_video_capability(bool f) { video_capability_ = f; }
85 void set_camera_capability(bool f) { camera_capability_ = f; }
86 void set_caps_node(const std::string& f) { caps_node_ = f; }
87 void set_version(const std::string& v) { version_ = v; }
88 void set_feedback_probation(bool f) { feedback_probation_ = f; }
89 void set_sent_time(const std::string& time) { sent_time_ = time; }
91 void UpdateWith(const PresenceStatus& new_value);
93 bool HasQuietStatus() const {
96 return !(QuietStatus().empty());
99 // Knowledge of other clients' silly automatic status strings -
101 std::string QuietStatus() const {
102 if (jid_.resource().find("Psi") != std::string::npos) {
103 if (status_ == "Online" ||
104 status_.find("Auto Status") != std::string::npos)
107 if (jid_.resource().find("Gaim") != std::string::npos) {
108 if (status_ == "Sorry, I ran out for a bit!")
111 return TrimStatus(status_);
114 std::string ExplicitStatus() const {
115 std::string result = QuietStatus();
116 if (result.empty()) {
117 result = ShowStatus();
122 std::string ShowStatus() const {
140 result = "Available";
147 static std::string TrimStatus(const std::string& st) {
150 bool collapsing = true;
151 for (unsigned int i = 0; i < s.length(); i+= 1) {
152 if (s[i] <= ' ' && s[i] >= 0) {
168 if (collapsing && j > 0) {
171 s.erase(j, s.length());
184 bool feedback_probation_;
186 // capabilities (valid only if know_capabilities_
187 bool know_capabilities_;
188 bool voice_capability_;
189 bool pmuc_capability_;
190 bool video_capability_;
191 bool camera_capability_;
192 std::string caps_node_;
193 std::string version_;
195 std::string sent_time_; // from the jabber:x:delay element
198 class MucPresenceStatus : public PresenceStatus {
204 #endif // THIRD_PARTY_LIBJINGLE_FILES_TALK_XMPP_PRESENCESTATUS_H_