[empathy] Add more information to EmpathyChatroom



commit 1df3cf4311df50cbe3c3909010828b068da53f1d
Author: Pierre-Luc Beaudoin <pierre-luc pierlux com>
Date:   Wed Dec 17 17:41:30 2008 -0500

    Add more information to EmpathyChatroom
    - Invite Only
    - Require password
    - Subject
    - Member count
---
 libempathy/empathy-chatroom.c    |  205 +++++++++++++++++++++++++++++++++++++-
 libempathy/empathy-chatroom.h    |   12 ++
 libempathy/empathy-tp-roomlist.c |   28 +++++
 3 files changed, 242 insertions(+), 3 deletions(-)

diff --git a/libempathy/empathy-chatroom.c b/libempathy/empathy-chatroom.c
index ef89994..8ffd8a5 100644
--- a/libempathy/empathy-chatroom.c
+++ b/libempathy/empathy-chatroom.c
@@ -37,6 +37,10 @@ typedef struct {
 	gboolean   auto_connect;
 	gboolean favorite;
 	EmpathyTpChat *tp_chat;
+	gchar *subject;
+	guint members_count;
+	gboolean invite_only;
+	gboolean need_password;
 } EmpathyChatroomPriv;
 
 
@@ -58,6 +62,10 @@ enum {
 	PROP_AUTO_CONNECT,
 	PROP_FAVORITE,
 	PROP_TP_CHAT,
+	PROP_SUBJECT,
+	PROP_MEMBERS_COUNT,
+	PROP_NEED_PASSWORD,
+	PROP_INVITE_ONLY
 };
 
 G_DEFINE_TYPE (EmpathyChatroom, empathy_chatroom, G_TYPE_OBJECT);
@@ -123,6 +131,56 @@ empathy_chatroom_class_init (EmpathyChatroomClass *klass)
 							      EMPATHY_TYPE_TP_CHAT,
 							      G_PARAM_READWRITE));
 
+  g_object_class_install_property (object_class,
+      PROP_SUBJECT,
+      g_param_spec_string ("subject",
+        "Subject",
+        "The chatroom's subject",
+        "",
+        G_PARAM_READWRITE |
+        G_PARAM_CONSTRUCT |
+        G_PARAM_STATIC_NAME |
+        G_PARAM_STATIC_NICK |
+        G_PARAM_STATIC_BLURB));
+
+  g_object_class_install_property (object_class,
+      PROP_MEMBERS_COUNT,
+      g_param_spec_uint ("members-count",
+        "Members count",
+        "The chatroom's members count",
+        0,
+        G_MAXUINT,
+        0,
+        G_PARAM_READWRITE |
+        G_PARAM_CONSTRUCT |
+        G_PARAM_STATIC_NAME |
+        G_PARAM_STATIC_NICK |
+        G_PARAM_STATIC_BLURB));
+
+  g_object_class_install_property (object_class,
+      PROP_INVITE_ONLY,
+      g_param_spec_boolean ("invite-only",
+        "Invite Only",
+        "The chatroom is invite only",
+        FALSE,
+        G_PARAM_READWRITE |
+        G_PARAM_CONSTRUCT |
+        G_PARAM_STATIC_NAME |
+        G_PARAM_STATIC_NICK |
+        G_PARAM_STATIC_BLURB));
+
+  g_object_class_install_property (object_class,
+      PROP_NEED_PASSWORD,
+      g_param_spec_boolean ("need-password",
+        "Password Needed",
+        "The chatroom is password protected",
+        FALSE,
+        G_PARAM_READWRITE |
+        G_PARAM_CONSTRUCT |
+        G_PARAM_STATIC_NAME |
+        G_PARAM_STATIC_NICK |
+        G_PARAM_STATIC_BLURB));
+
 	g_type_class_add_private (object_class, sizeof (EmpathyChatroomPriv));
 }
 
@@ -175,12 +233,24 @@ chatroom_get_property (GObject    *object,
 	case PROP_AUTO_CONNECT:
 		g_value_set_boolean (value, priv->auto_connect);
 		break;
-  case PROP_FAVORITE:
-    g_value_set_boolean (value, priv->favorite);
-    break;
+	case PROP_FAVORITE:
+		g_value_set_boolean (value, priv->favorite);
+		break;
 	case PROP_TP_CHAT:
 		g_value_set_object (value, priv->tp_chat);
 		break;
+  case PROP_SUBJECT:
+    g_value_set_string (value, priv->subject);
+    break;
+  case PROP_MEMBERS_COUNT:
+    g_value_set_uint (value, priv->members_count);
+    break;
+  case PROP_INVITE_ONLY:
+    g_value_set_boolean (value, priv->invite_only);
+    break;
+  case PROP_NEED_PASSWORD:
+    g_value_set_boolean (value, priv->need_password);
+    break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 		break;
@@ -238,6 +308,22 @@ chatroom_set_property (GObject      *object,
 		}
 		break;
 	}
+  case PROP_SUBJECT:
+    empathy_chatroom_set_subject (EMPATHY_CHATROOM (object),
+        g_value_get_string (value));
+    break;
+  case PROP_MEMBERS_COUNT:
+    empathy_chatroom_set_members_count (EMPATHY_CHATROOM (object),
+        g_value_get_uint (value));
+    break;
+  case PROP_NEED_PASSWORD:
+    empathy_chatroom_set_need_password (EMPATHY_CHATROOM (object),
+        g_value_get_boolean (value));
+    break;
+  case PROP_INVITE_ONLY:
+    empathy_chatroom_set_invite_only (EMPATHY_CHATROOM (object),
+        g_value_get_boolean (value));
+    break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 		break;
@@ -432,3 +518,116 @@ empathy_chatroom_get_tp_chat (EmpathyChatroom *chatroom) {
 
 	return priv->tp_chat;
 }
+
+const gchar *
+empathy_chatroom_get_subject (EmpathyChatroom *chatroom)
+{
+  EmpathyChatroomPriv *priv;
+
+  g_return_val_if_fail (EMPATHY_IS_CHATROOM (chatroom), NULL);
+
+  priv = GET_PRIV (chatroom);
+
+  return priv->subject;
+}
+
+void
+empathy_chatroom_set_subject (EmpathyChatroom *chatroom,
+                              const gchar *subject)
+{
+  EmpathyChatroomPriv *priv;
+
+  g_return_if_fail (EMPATHY_IS_CHATROOM (chatroom));
+
+  priv = GET_PRIV (chatroom);
+
+  g_free (priv->subject);
+  priv->subject = NULL;
+
+  if (subject)
+    priv->subject = g_strdup (subject);
+
+  g_object_notify (G_OBJECT (chatroom), "subject");
+}
+
+guint
+empathy_chatroom_get_members_count (EmpathyChatroom *chatroom)
+{
+  EmpathyChatroomPriv *priv;
+
+  g_return_val_if_fail (EMPATHY_IS_CHATROOM (chatroom), 0);
+
+  priv = GET_PRIV (chatroom);
+
+  return priv->members_count;
+}
+
+void
+empathy_chatroom_set_members_count (EmpathyChatroom *chatroom,
+                                    guint count)
+{
+  EmpathyChatroomPriv *priv;
+
+  g_return_if_fail (EMPATHY_IS_CHATROOM (chatroom));
+
+  priv = GET_PRIV (chatroom);
+
+  priv->members_count = count;
+
+  g_object_notify (G_OBJECT (chatroom), "members-count");
+}
+
+gboolean
+empathy_chatroom_get_need_password (EmpathyChatroom *chatroom)
+{
+  EmpathyChatroomPriv *priv;
+
+  g_return_val_if_fail (EMPATHY_IS_CHATROOM (chatroom), FALSE);
+
+  priv = GET_PRIV (chatroom);
+
+  return priv->need_password;
+}
+
+void
+empathy_chatroom_set_need_password (EmpathyChatroom *chatroom,
+                                    gboolean need_password)
+{
+  EmpathyChatroomPriv *priv;
+
+  g_return_if_fail (EMPATHY_IS_CHATROOM (chatroom));
+
+  priv = GET_PRIV (chatroom);
+
+  priv->need_password = need_password;
+
+  g_object_notify (G_OBJECT (chatroom), "need-password");
+}
+
+gboolean
+empathy_chatroom_get_invite_only (EmpathyChatroom *chatroom)
+{
+  EmpathyChatroomPriv *priv;
+
+  g_return_val_if_fail (EMPATHY_IS_CHATROOM (chatroom), FALSE);
+
+  priv = GET_PRIV (chatroom);
+
+  return priv->invite_only;
+}
+
+void
+empathy_chatroom_set_invite_only (EmpathyChatroom *chatroom,
+                                  gboolean invite_only)
+{
+  EmpathyChatroomPriv *priv;
+
+  g_return_if_fail (EMPATHY_IS_CHATROOM (chatroom));
+
+  priv = GET_PRIV (chatroom);
+
+  priv->invite_only = invite_only;
+
+  g_object_notify (G_OBJECT (chatroom), "invite-only");
+}
+
diff --git a/libempathy/empathy-chatroom.h b/libempathy/empathy-chatroom.h
index 3261c8d..08e3bc1 100644
--- a/libempathy/empathy-chatroom.h
+++ b/libempathy/empathy-chatroom.h
@@ -69,6 +69,18 @@ void            empathy_chatroom_set_name         (EmpathyChatroom *chatroom,
 gboolean        empathy_chatroom_get_auto_connect (EmpathyChatroom *chatroom);
 void            empathy_chatroom_set_auto_connect (EmpathyChatroom *chatroom,
 						   gboolean         auto_connect);
+const gchar *   empathy_chatroom_get_subject      (EmpathyChatroom *chatroom);
+void            empathy_chatroom_set_subject      (EmpathyChatroom *chatroom,
+						   const gchar     *subject);
+guint           empathy_chatroom_get_members_count (EmpathyChatroom *chatroom);
+void            empathy_chatroom_set_members_count (EmpathyChatroom *chatroom,
+						    guint            count);
+gboolean        empathy_chatroom_get_need_password (EmpathyChatroom *chatroom);
+void            empathy_chatroom_set_need_password (EmpathyChatroom *chatroom,
+						    gboolean         need_password);
+gboolean        empathy_chatroom_get_invite_only  (EmpathyChatroom *chatroom);
+void            empathy_chatroom_set_invite_only  (EmpathyChatroom *chatroom,
+						   gboolean         invite_only);
 gboolean        empathy_chatroom_equal            (gconstpointer    v1,
 						   gconstpointer    v2);
 EmpathyTpChat * empathy_chatroom_get_tp_chat      (EmpathyChatroom *chatroom);
diff --git a/libempathy/empathy-tp-roomlist.c b/libempathy/empathy-tp-roomlist.c
index a1583c0..fc2526f 100644
--- a/libempathy/empathy-tp-roomlist.c
+++ b/libempathy/empathy-tp-roomlist.c
@@ -122,6 +122,10 @@ tp_roomlist_got_rooms_cb (TpChannel       *channel,
 	for (i = 0; i < rooms->len; i++) {
 		const GValue *room_name_value;
 		const GValue *handle_name_value;
+		const GValue *room_members_value;
+		const GValue *room_subject_value;
+		const GValue *room_invite_value;
+		const GValue *room_password_value;
 		GValueArray  *room_struct;
 		guint         handle;
 		const gchar  *channel_type;
@@ -134,6 +138,10 @@ tp_roomlist_got_rooms_cb (TpChannel       *channel,
 		info = g_value_get_boxed (g_value_array_get_nth (room_struct, 2));
 		room_name_value = g_hash_table_lookup (info, "name");
 		handle_name_value = g_hash_table_lookup (info, "handle-name");
+		room_subject_value = g_hash_table_lookup (info, "subject");
+		room_members_value = g_hash_table_lookup (info, "members");
+		room_invite_value = g_hash_table_lookup (info, "invite-only");
+		room_password_value = g_hash_table_lookup (info, "password");
 
 		if (tp_strdiff (channel_type, TP_IFACE_CHANNEL_TYPE_TEXT)) {
 			continue;
@@ -146,6 +154,26 @@ tp_roomlist_got_rooms_cb (TpChannel       *channel,
 						   g_value_get_string (room_name_value));
 		}
 
+		if (room_members_value != NULL) {
+			empathy_chatroom_set_members_count (chatroom,
+						   g_value_get_uint (room_members_value));
+		}
+
+		if (room_subject_value != NULL) {
+			empathy_chatroom_set_subject (chatroom,
+						   g_value_get_string (room_subject_value));
+		}
+
+		if (room_invite_value != NULL) {
+			empathy_chatroom_set_invite_only (chatroom,
+						   g_value_get_boolean (room_invite_value));
+		}
+
+		if (room_password_value != NULL) {
+			empathy_chatroom_set_need_password (chatroom,
+						   g_value_get_boolean (room_password_value));
+		}
+
 		if (handle_name_value != NULL) {
 			empathy_chatroom_set_room (chatroom,
 						   g_value_get_string (handle_name_value));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]