2 * Copyright (C) 2010-2011 Collabora Ltd.
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 2.1 of the License, or
7 * (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library. If not, see <http://www.gnu.org/licenses/>.
18 * Travis Reitter <travis.reitter@collabora.co.uk>
24 * The possible presence states an object implementing {@link PresenceDetails}
27 * These closely follow the
28 * [[http://telepathy.freedesktop.org/spec/Connection_Interface_Simple_Presence.html#Connection_Presence_Type|SimplePresence]]
29 * interface in the Telepathy specification.
31 public enum Folks.PresenceType
50 * away from keyboard for an extended period of time
54 * also known as "invisible" or "appear offline"
58 * at keyboard, but too busy to chat
62 * presence not received from server
66 * an error occurred with fetching the presence
72 * Interface exposing a {@link Persona}'s or {@link Individual}'s presence;
73 * their current availability, such as for chatting.
75 * If the {@link Backend} providing the {@link Persona} doesn't support
76 * presence, the {@link Persona}'s `presence_type` will be set to
77 * {@link PresenceType.UNSET} and their `presence_message` will be an empty
80 public interface Folks.PresenceDetails : Object
83 * The contact's presence type.
85 * Each contact can have one and only one presence type at any one time,
86 * representing their availability for communication. The default presence
87 * type is {@link PresenceType.UNSET}.
89 public abstract Folks.PresenceType presence_type
91 get; set; default = Folks.PresenceType.UNSET;
95 * The contact's presence message.
97 * This is a short message written by the contact to add detail to their
98 * presence type ({@link Folks.PresenceDetails.presence_type}). If the contact
99 * hasn't set a message, it will be an empty string.
101 public abstract string presence_message { get; set; default = ""; }
104 * The contact's detailed presence status.
106 * This is a more detailed representation of the contact's presence than
107 * {@link PresenceDetails.presence_type}. It may be empty, or one of a
108 * well-known set of strings, as defined in the Telepathy specification:
109 * [[http://telepathy.freedesktop.org/spec/Connection_Interface_Simple_Presence.html#description|Telepathy Specification]]
113 public abstract string presence_status { get; set; default = ""; }
115 /* Rank the presence types for comparison purposes, with higher numbers
116 * meaning more available */
117 private static int _type_availability (PresenceType type)
121 case PresenceType.UNSET:
123 case PresenceType.UNKNOWN:
125 case PresenceType.ERROR:
127 case PresenceType.OFFLINE:
129 case PresenceType.HIDDEN:
131 case PresenceType.EXTENDED_AWAY:
133 case PresenceType.AWAY:
135 case PresenceType.BUSY:
137 case PresenceType.AVAILABLE:
145 * The default message for a presence type.
149 public static string get_default_message_from_type (PresenceType type)
154 case PresenceType.UNKNOWN:
155 return _("Unknown status");
156 case PresenceType.OFFLINE:
158 case PresenceType.UNSET:
160 case PresenceType.ERROR:
162 case PresenceType.AVAILABLE:
163 return _("Available");
164 case PresenceType.AWAY:
166 case PresenceType.EXTENDED_AWAY:
167 return _("Extended away");
168 case PresenceType.BUSY:
170 case PresenceType.HIDDEN:
176 * Compare two {@link PresenceType}s.
178 * `0` will be returned if the types are equal, a positive number will be
179 * returned if `type_a` is more available than `type_b`, and a negative
180 * number will be returned if the opposite is true.
182 * @param type_a the first {@link PresenceType} to compare
183 * @param type_b the second {@link PresenceType} to compare
184 * @return a number representing the similarity of the two types
187 public static int typecmp (PresenceType type_a, PresenceType type_b)
189 return (PresenceDetails._type_availability (type_a) -
190 PresenceDetails._type_availability (type_b));
194 * Whether the contact is online.
196 * This will be `true` if the contact's presence type is higher than
197 * {@link PresenceType.OFFLINE}, as determined by
198 * {@link PresenceDetails.typecmp}.
200 * @return `true` if the contact is online, `false` otherwise
202 public bool is_online ()
204 return (typecmp (this.presence_type, PresenceType.OFFLINE) > 0);