[Telepathy-commits] [telepathy-glib/master] Add tp_connection_presence_type_cmp() for presenceness compare.
Xavier Claessens
xclaesse at gmail.com
Mon Sep 22 05:08:11 PDT 2008
---
docs/reference/telepathy-glib-sections.txt | 1 +
telepathy-glib/connection.c | 59 ++++++++++++++++++++++++++++
telepathy-glib/connection.h | 3 +
3 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/docs/reference/telepathy-glib-sections.txt b/docs/reference/telepathy-glib-sections.txt
index a0bb2b5..b2c06ad 100644
--- a/docs/reference/telepathy-glib-sections.txt
+++ b/docs/reference/telepathy-glib-sections.txt
@@ -2044,6 +2044,7 @@ TpConnectionWhenReadyCb
tp_connection_call_when_ready
tp_connection_get_status
tp_connection_init_known_interfaces
+tp_connection_presence_type_cmp
TpConnection
TpConnectionClass
TP_UNKNOWN_CONNECTION_STATUS
diff --git a/telepathy-glib/connection.c b/telepathy-glib/connection.c
index 1e21d73..395afd0 100644
--- a/telepathy-glib/connection.c
+++ b/telepathy-glib/connection.c
@@ -1023,3 +1023,62 @@ tp_connection_call_when_ready (TpConnection *self,
G_CALLBACK (cwr_ready), ctx);
}
}
+
+static guint
+fix_presence_type_order (TpConnectionPresenceType type)
+{
+ /* available > busy > away > xa > hidden > offline > error > unknown > unset */
+ switch (type)
+ {
+ case TP_CONNECTION_PRESENCE_TYPE_UNSET:
+ return 0;
+ case TP_CONNECTION_PRESENCE_TYPE_UNKNOWN:
+ return 1;
+ case TP_CONNECTION_PRESENCE_TYPE_ERROR:
+ return 2;
+ case TP_CONNECTION_PRESENCE_TYPE_OFFLINE:
+ return 3;
+ case TP_CONNECTION_PRESENCE_TYPE_HIDDEN:
+ return 4;
+ case TP_CONNECTION_PRESENCE_TYPE_EXTENDED_AWAY:
+ return 5;
+ case TP_CONNECTION_PRESENCE_TYPE_AWAY:
+ return 6;
+ case TP_CONNECTION_PRESENCE_TYPE_BUSY:
+ return 7;
+ case TP_CONNECTION_PRESENCE_TYPE_AVAILABLE:
+ return 8;
+ }
+ g_assert_not_reached ();
+}
+
+/**
+ * tp_connection_presence_type_cmp:
+ * @p1: a #TpConnectionPresenceType
+ * @p2: a #TpConnectionPresenceType
+ *
+ * Compares @p1 and @p2 like strcmp(). @p1 > @p2 means @p1 is more available
+ * than @p2.
+ *
+ * Returns: -1, 0 or 1, if p1 is <, == or > than p2.
+ *
+ * Since: 0.7.UNRELEASED
+ */
+gint
+tp_connection_presence_type_cmp (TpConnectionPresenceType p1,
+ TpConnectionPresenceType p2)
+{
+ guint fixed_p1;
+ guint fixed_p2;
+
+ fixed_p1 = fix_presence_type_order (p1);
+ fixed_p2 = fix_presence_type_order (p2);
+
+ if (fixed_p1 < fixed_p2)
+ return -1;
+
+ if (fixed_p1 > fixed_p2)
+ return +1;
+
+ return 0;
+}
diff --git a/telepathy-glib/connection.h b/telepathy-glib/connection.h
index c133523..f596c03 100644
--- a/telepathy-glib/connection.h
+++ b/telepathy-glib/connection.h
@@ -97,6 +97,9 @@ void tp_list_connection_names (TpDBusDaemon *bus_daemon,
void tp_connection_init_known_interfaces (void);
+gint tp_connection_presence_type_cmp (TpConnectionPresenceType p1,
+ TpConnectionPresenceType p2);
+
G_END_DECLS
#include <telepathy-glib/_gen/tp-cli-connection.h>
--
1.5.6.5
More information about the Telepathy-commits
mailing list