~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/libjingle/talk/examples/call/status.h

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * libjingle
 
3
 * Copyright 2004--2005, Google Inc.
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions are met:
 
7
 *
 
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.
 
15
 *
 
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.
 
26
 */
 
27
 
 
28
#ifndef _STATUS_H_
 
29
#define _STATUS_H_
 
30
 
 
31
#include "talk/xmpp/jid.h"
 
32
#include "talk/xmpp/constants.h"
 
33
 
 
34
namespace buzz {
 
35
 
 
36
class Status {
 
37
public:
 
38
  Status()
 
39
      : pri_(0),
 
40
        show_(SHOW_NONE),
 
41
        available_(false),
 
42
        e_code_(0),
 
43
        feedback_probation_(false),
 
44
        know_capabilities_(false),
 
45
        voice_capability_(false),
 
46
        pmuc_capability_(false),
 
47
        video_capability_(false),
 
48
        camera_capability_(false) {
 
49
  }
 
50
 
 
51
  ~Status() {}
 
52
 
 
53
  // These are arranged in "priority order", i.e., if we see
 
54
  // two statuses at the same priority but with different Shows,
 
55
  // we will show the one with the highest show in the following
 
56
  // order.
 
57
  enum Show {
 
58
    SHOW_NONE     = 0,
 
59
    SHOW_OFFLINE  = 1,
 
60
    SHOW_XA       = 2,
 
61
    SHOW_AWAY     = 3,
 
62
    SHOW_DND      = 4,
 
63
    SHOW_ONLINE   = 5,
 
64
    SHOW_CHAT     = 6,
 
65
  };
 
66
 
 
67
  const Jid& jid() const { return jid_; }
 
68
  int priority() const { return pri_; }
 
69
  Show show() const { return show_; }
 
70
  const std::string& status() const { return status_; }
 
71
  const std::string& nick() const { return nick_; }
 
72
  bool available() const { return available_ ; }
 
73
  int error_code() const { return e_code_; }
 
74
  const std::string& error_string() const { return e_str_; }
 
75
  bool know_capabilities() const { return know_capabilities_; }
 
76
  bool voice_capability() const { return voice_capability_; }
 
77
  bool pmuc_capability() const { return pmuc_capability_; }
 
78
  bool video_capability() const { return video_capability_; }
 
79
  bool camera_capability() const { return camera_capability_; }
 
80
  const std::string& caps_node() const { return caps_node_; }
 
81
  const std::string& version() const { return version_; }
 
82
  bool feedback_probation() const { return feedback_probation_; }
 
83
  const std::string& sent_time() const { return sent_time_; }
 
84
 
 
85
  void set_jid(const Jid& jid) { jid_ = jid; }
 
86
  void set_priority(int pri) { pri_ = pri; }
 
87
  void set_show(Show show) { show_ = show; }
 
88
  void set_status(const std::string& status) { status_ = status; }
 
89
  void set_nick(const std::string& nick) { nick_ = nick; }
 
90
  void set_available(bool a) { available_ = a; }
 
91
  void set_error(int e_code, const std::string e_str)
 
92
      { e_code_ = e_code; e_str_ = e_str; }
 
93
  void set_know_capabilities(bool f) { know_capabilities_ = f; }
 
94
  void set_voice_capability(bool f) { voice_capability_ = f; }
 
95
  void set_pmuc_capability(bool f) { pmuc_capability_ = f; }
 
96
  void set_video_capability(bool f) { video_capability_ = f; }
 
97
  void set_camera_capability(bool f) { camera_capability_ = f; }
 
98
  void set_caps_node(const std::string& f) { caps_node_ = f; }
 
99
  void set_version(const std::string& v) { version_ = v; }
 
100
  void set_feedback_probation(bool f) { feedback_probation_ = f; }
 
101
  void set_sent_time(const std::string& time) { sent_time_ = time; }
 
102
 
 
103
  void UpdateWith(const Status& new_value) {
 
104
    if (!new_value.know_capabilities()) {
 
105
       bool k = know_capabilities();
 
106
       bool p = voice_capability();
 
107
       std::string node = caps_node();
 
108
       std::string v = version();
 
109
 
 
110
       *this = new_value;
 
111
 
 
112
       set_know_capabilities(k);
 
113
       set_caps_node(node);
 
114
       set_voice_capability(p);
 
115
       set_version(v);
 
116
    }
 
117
    else {
 
118
      *this = new_value;
 
119
    }
 
120
  }
 
121
 
 
122
  bool HasQuietStatus() const {
 
123
    if (status_.empty())
 
124
      return false;
 
125
    return !(QuietStatus().empty());
 
126
  }
 
127
 
 
128
  // Knowledge of other clients' silly automatic status strings -
 
129
  // Don't show these.
 
130
  std::string QuietStatus() const {
 
131
    if (jid_.resource().find("Psi") != std::string::npos) {
 
132
      if (status_ == "Online" ||
 
133
          status_.find("Auto Status") != std::string::npos)
 
134
        return STR_EMPTY;
 
135
    }
 
136
    if (jid_.resource().find("Gaim") != std::string::npos) {
 
137
      if (status_ == "Sorry, I ran out for a bit!")
 
138
        return STR_EMPTY;
 
139
    }
 
140
    return TrimStatus(status_);
 
141
  }
 
142
 
 
143
  std::string ExplicitStatus() const {
 
144
    std::string result = QuietStatus();
 
145
    if (result.empty()) {
 
146
      result = ShowStatus();
 
147
    }
 
148
    return result;
 
149
  }
 
150
 
 
151
  std::string ShowStatus() const {
 
152
    std::string result;
 
153
    if (!available()) {
 
154
      result = "Offline";
 
155
    }
 
156
    else {
 
157
      switch (show()) {
 
158
        case SHOW_AWAY:
 
159
        case SHOW_XA:
 
160
          result = "Idle";
 
161
          break;
 
162
        case SHOW_DND:
 
163
          result = "Busy";
 
164
          break;
 
165
        case SHOW_CHAT:
 
166
          result = "Chatty";
 
167
          break;
 
168
        default:
 
169
          result = "Available";
 
170
          break;
 
171
      }
 
172
    }
 
173
    return result;
 
174
  }
 
175
 
 
176
  static std::string TrimStatus(const std::string& st) {
 
177
    std::string s(st);
 
178
    int j = 0;
 
179
    bool collapsing = true;
 
180
    for (unsigned int i = 0; i < s.length(); i+= 1) {
 
181
      if (s[i] <= ' ' && s[i] >= 0) {
 
182
        if (collapsing) {
 
183
          continue;
 
184
        }
 
185
        else {
 
186
          s[j] = ' ';
 
187
          j += 1;
 
188
          collapsing = true;
 
189
        }
 
190
      }
 
191
      else {
 
192
        s[j] = s[i];
 
193
        j += 1;
 
194
        collapsing = false;
 
195
      }
 
196
    }
 
197
    if (collapsing && j > 0) {
 
198
      j -= 1;
 
199
    }
 
200
    s.erase(j, s.length());
 
201
    return s;
 
202
  }
 
203
 
 
204
private:
 
205
  Jid jid_;
 
206
  int pri_;
 
207
  Show show_;
 
208
  std::string status_;
 
209
  std::string nick_;
 
210
  bool available_;
 
211
  int e_code_;
 
212
  std::string e_str_;
 
213
  bool feedback_probation_;
 
214
 
 
215
  // capabilities (valid only if know_capabilities_
 
216
  bool know_capabilities_;
 
217
  bool voice_capability_;
 
218
  bool pmuc_capability_;
 
219
  bool video_capability_;
 
220
  bool camera_capability_;
 
221
  std::string caps_node_;
 
222
  std::string version_;
 
223
 
 
224
  std::string sent_time_; // from the jabber:x:delay element
 
225
};
 
226
 
 
227
class MucStatus : public Status {
 
228
};
 
229
 
 
230
}
 
231
 
 
232
 
 
233
#endif