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 * Compare two {@link PresenceType}s.
147 * `0` will be returned if the types are equal, a positive number will be
148 * returned if `type_a` is more available than `type_b`, and a negative
149 * number will be returned if the opposite is true.
151 * @param type_a the first {@link PresenceType} to compare
152 * @param type_b the second {@link PresenceType} to compare
153 * @return a number representing the similarity of the two types
156 public static int typecmp (PresenceType type_a, PresenceType type_b)
158 return (PresenceDetails._type_availability (type_a) -
159 PresenceDetails._type_availability (type_b));
163 * Whether the contact is online.
165 * This will be `true` if the contact's presence type is higher than
166 * {@link PresenceType.OFFLINE}, as determined by
167 * {@link PresenceDetails.typecmp}.
169 * @return `true` if the contact is online, `false` otherwise
171 public bool is_online ()
173 return (typecmp (this.presence_type, PresenceType.OFFLINE) > 0);