summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJonny Lamb <jonny.lamb@collabora.co.uk>2012-05-14 21:09:39 +0100
committerJonny Lamb <jonny.lamb@collabora.co.uk>2012-05-15 10:58:23 +0100
commitc718f11c8dc1e8270fb5d101c366df97f074e315 (patch)
treeb5ab1b68d3e700cddca93b3a97e3643cce6842cb /src
parent5430aa1495a9efb0e9b9ad030fc7c66655aac064 (diff)
muc-channel: add initial RoomConfig1 implementation
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/idle-muc-channel.c166
-rw-r--r--src/idle-muc-channel.h11
-rw-r--r--src/room-config.c125
-rw-r--r--src/room-config.h61
5 files changed, 365 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 466a362..9a2eb99 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -24,6 +24,8 @@ libidle_convenience_la_SOURCES = \
idle-muc-channel.h \
idle-muc-manager.c \
idle-muc-manager.h \
+ room-config.c \
+ room-config.h \
idle-parser.c \
idle-parser.h \
protocol.c \
diff --git a/src/idle-muc-channel.c b/src/idle-muc-channel.c
index abbae29..bd3029e 100644
--- a/src/idle-muc-channel.c
+++ b/src/idle-muc-channel.c
@@ -43,6 +43,7 @@
#include "idle-connection.h"
#include "idle-debug.h"
#include "idle-text.h"
+#include "room-config.h"
static void _password_iface_init(gpointer, gpointer);
static void subject_iface_init(gpointer, gpointer);
@@ -57,6 +58,8 @@ G_DEFINE_TYPE_WITH_CODE(IdleMUCChannel, idle_muc_channel, TP_TYPE_BASE_CHANNEL,
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_MESSAGES, tp_message_mixin_messages_iface_init);
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_ROOM, NULL);
G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_SUBJECT, subject_iface_init);
+ G_IMPLEMENT_INTERFACE (TP_TYPE_SVC_CHANNEL_INTERFACE_ROOM_CONFIG,
+ tp_base_room_config_iface_init);
)
/* property enum */
@@ -149,6 +152,7 @@ static const gchar *muc_channel_interfaces[] = {
TP_IFACE_CHANNEL_INTERFACE_MESSAGES,
TP_IFACE_CHANNEL_INTERFACE_ROOM,
TP_IFACE_CHANNEL_INTERFACE_SUBJECT,
+ TP_IFACE_CHANNEL_INTERFACE_ROOM_CONFIG,
NULL
};
@@ -201,6 +205,8 @@ static guint signals[LAST_SIGNAL] = {0};
struct _IdleMUCChannelPrivate {
const gchar *channel_name;
+ TpBaseRoomConfig *room_config;
+
IdleMUCState state;
IRCChannelModeState mode_state;
@@ -292,6 +298,30 @@ idle_muc_channel_constructed (GObject *obj)
initiator, TP_CHANNEL_GROUP_CHANGE_REASON_NONE);
tp_intset_destroy (remote);
}
+
+ {
+ TpBaseRoomConfigProperty mutable_properties[] = {
+ TP_BASE_ROOM_CONFIG_INVITE_ONLY,
+ TP_BASE_ROOM_CONFIG_MODERATED,
+ TP_BASE_ROOM_CONFIG_LIMIT,
+ TP_BASE_ROOM_CONFIG_PRIVATE,
+ TP_BASE_ROOM_CONFIG_PASSWORD_PROTECTED,
+ TP_BASE_ROOM_CONFIG_PASSWORD,
+ };
+ guint i;
+
+ priv->room_config =
+ (TpBaseRoomConfig *) idle_room_config_new ((TpBaseChannel *) self);
+ for (i = 0; i < G_N_ELEMENTS (mutable_properties); i++)
+ tp_base_room_config_set_property_mutable (priv->room_config,
+ mutable_properties[i], TRUE);
+
+ tp_base_room_config_set_can_update_configuration (
+ priv->room_config, TRUE);
+
+ /* Just to get those mutable properties out there. */
+ tp_base_room_config_emit_properties_changed (priv->room_config);
+ }
}
static void
@@ -438,6 +468,8 @@ static void idle_muc_channel_class_init (IdleMUCChannelClass *idle_muc_channel_c
tp_group_mixin_init_dbus_properties (object_class);
tp_group_mixin_class_allow_self_removal (object_class);
+ tp_base_room_config_register_class (base_channel_class);
+
tp_dbus_properties_mixin_implement_interface (object_class,
TP_IFACE_QUARK_CHANNEL_INTERFACE_ROOM,
tp_dbus_properties_mixin_getter_gobject_properties, NULL,
@@ -457,6 +489,8 @@ void idle_muc_channel_dispose (GObject *object) {
priv->dispose_has_run = TRUE;
+ tp_clear_object (&priv->room_config);
+
if (G_OBJECT_CLASS (idle_muc_channel_parent_class)->dispose)
G_OBJECT_CLASS (idle_muc_channel_parent_class)->dispose (object);
}
@@ -2116,3 +2150,135 @@ subject_iface_init (
/* TODO: remove this, it's just to squash unusedness warnings. */
_properties_iface_init (NULL, NULL);
}
+
+void
+idle_muc_channel_update_configuration_async (
+ IdleMUCChannel *self,
+ GHashTable *validated_properties,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ IdleMUCChannelPrivate *priv = self->priv;
+ GSimpleAsyncResult *result = g_simple_async_result_new ((GObject *) self,
+ callback, user_data, idle_muc_channel_update_configuration_async);
+ const gchar *password;
+
+ /* do the quick ones */
+
+#define DO_QUICK_BOOLEAN(prop, name, irc_mode) \
+ if (g_hash_table_lookup (validated_properties, GUINT_TO_POINTER (prop)) != NULL) \
+ { \
+ gboolean value = tp_asv_get_boolean (validated_properties, \
+ GUINT_TO_POINTER (prop), NULL); \
+ gboolean current; \
+ g_object_get (priv->room_config, \
+ name, &current, \
+ NULL); \
+ if (current != value) \
+ { \
+ gchar *cmd = g_strdup_printf ("MODE %s %s%s", priv->channel_name, \
+ value ? "+" : "-", irc_mode); \
+ send_command (self, cmd); \
+ g_free (cmd); \
+ } \
+ }
+
+ DO_QUICK_BOOLEAN (TP_BASE_ROOM_CONFIG_INVITE_ONLY, "invite-only", "i");
+ DO_QUICK_BOOLEAN (TP_BASE_ROOM_CONFIG_MODERATED, "moderated", "m");
+ DO_QUICK_BOOLEAN (TP_BASE_ROOM_CONFIG_PRIVATE, "private", "s");
+#undef DO_QUICK_BOOLEAN
+
+ /* now the rest */
+
+ if (g_hash_table_lookup (validated_properties,
+ GUINT_TO_POINTER (TP_BASE_ROOM_CONFIG_LIMIT)) != NULL)
+ {
+ guint limit = tp_asv_get_uint32 (validated_properties,
+ GUINT_TO_POINTER (TP_BASE_ROOM_CONFIG_LIMIT), NULL);
+ gchar *cmd = NULL;
+ guint current;
+
+ g_object_get (priv->room_config,
+ "limit", &current,
+ NULL);
+
+ if (limit != current)
+ {
+ /* a non-zero limit means we want a limit enabled, so let's
+ * set it. if the limit is zero let's disable the limit. */
+ if (limit > 0)
+ cmd = g_strdup_printf ("MODE %s +l %u", priv->channel_name, limit);
+ else
+ cmd = g_strdup_printf ("MODE %s -l", priv->channel_name);
+ }
+
+ if (cmd != NULL)
+ send_command (self, cmd);
+ g_free (cmd);
+ }
+
+ /* if we got a new password, save it away for a rainy day */
+ password = tp_asv_get_string (validated_properties,
+ GUINT_TO_POINTER (TP_BASE_ROOM_CONFIG_PASSWORD));
+
+ if (g_hash_table_lookup (validated_properties,
+ GUINT_TO_POINTER (TP_BASE_ROOM_CONFIG_PASSWORD_PROTECTED)) != NULL)
+ {
+ /* okay we want to require or not require a password ... */
+ gboolean required = tp_asv_get_boolean (validated_properties,
+ GUINT_TO_POINTER (TP_BASE_ROOM_CONFIG_PASSWORD_PROTECTED), NULL);
+ gchar *cmd = NULL;
+
+ /* only set the password if we want to and if we have one
+ * (ie. not the default value */
+ if (required && password != NULL)
+ cmd = g_strdup_printf ("MODE %s +k %s", priv->channel_name, password);
+ else if (!required)
+ cmd = g_strdup_printf ("MODE %s -k", priv->channel_name);
+ /* deliberately unhandled case here is:
+ * required && (password == NULL) */
+
+ if (cmd != NULL)
+ send_command (self, cmd);
+
+ g_free (cmd);
+ }
+ else if (password != NULL)
+ {
+ /* we didn't set PasswordProtected but we did get the password,
+ * and the flags say we can set the password. let's do so */
+ gchar *cmd;
+
+ cmd = g_strdup_printf ("MODE %s +k %s", priv->channel_name, password);
+ send_command (self, cmd);
+ g_free (cmd);
+
+ /* so set PasswordProtected now */
+ g_object_set (priv->room_config,
+ "password-protected", TRUE,
+ NULL);
+ }
+
+ g_simple_async_result_complete_in_idle (result);
+ g_object_unref (result);
+}
+
+gboolean
+idle_muc_channel_update_configuration_finish (
+ IdleMUCChannel *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ GSimpleAsyncResult *simple;
+
+ simple = (GSimpleAsyncResult *) result;
+
+ if (g_simple_async_result_propagate_error (simple, error))
+ return FALSE;
+
+ g_return_val_if_fail (g_simple_async_result_is_valid (result,
+ G_OBJECT (self), idle_muc_channel_update_configuration_async),
+ FALSE);
+
+ return TRUE;
+}
diff --git a/src/idle-muc-channel.h b/src/idle-muc-channel.h
index ece24a3..f45efd9 100644
--- a/src/idle-muc-channel.h
+++ b/src/idle-muc-channel.h
@@ -22,6 +22,7 @@
#define __IDLE_MUC_CHANNEL_H__
#include <glib-object.h>
+#include <gio/gio.h>
#include <telepathy-glib/base-channel.h>
#include <telepathy-glib/enums.h>
@@ -100,6 +101,16 @@ void idle_muc_channel_topic_unset(IdleMUCChannel *chan);
gboolean idle_muc_channel_is_ready(IdleMUCChannel *chan);
+void idle_muc_channel_update_configuration_async (
+ IdleMUCChannel *self,
+ GHashTable *validated_properties,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean idle_muc_channel_update_configuration_finish (
+ IdleMUCChannel *self,
+ GAsyncResult *result,
+ GError **error);
+
G_END_DECLS
#endif /* #ifndef __IDLE_MUC_CHANNEL_H__*/
diff --git a/src/room-config.c b/src/room-config.c
new file mode 100644
index 0000000..32397e9
--- /dev/null
+++ b/src/room-config.c
@@ -0,0 +1,125 @@
+/*
+ * room-config.c - Channel.Interface.RoomConfig1 implementation
+ * Copyright © 2011-2012 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "room-config.h"
+#include "idle-muc-channel.h"
+
+#define IDLE_DEBUG_FLAG IDLE_DEBUG_MUC
+#include "idle-debug.h"
+
+static void idle_room_config_update_configuration_async (
+ TpBaseRoomConfig *base_config,
+ GHashTable *validated_properties,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+
+struct _IdleRoomConfigPrivate {
+ gpointer hi_dere;
+};
+
+G_DEFINE_TYPE (IdleRoomConfig, idle_room_config, TP_TYPE_BASE_ROOM_CONFIG)
+
+static void
+idle_room_config_password_protected_cb (GObject *object,
+ GParamSpec *pspec,
+ gpointer user_data)
+{
+ gboolean protected;
+
+ g_object_get (object,
+ "password-protected", &protected,
+ NULL);
+
+ if (!protected)
+ {
+ g_object_set (object,
+ "password", "",
+ NULL);
+ }
+}
+
+static void
+idle_room_config_init (IdleRoomConfig *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, IDLE_TYPE_ROOM_CONFIG,
+ IdleRoomConfigPrivate);
+
+ /* Let's reset the password back to the empty string when
+ * password-protected is set to False. */
+ g_signal_connect (self, "notify::password-protected",
+ G_CALLBACK (idle_room_config_password_protected_cb), NULL);
+}
+
+static void
+idle_room_config_class_init (IdleRoomConfigClass *klass)
+{
+ TpBaseRoomConfigClass *parent_class = TP_BASE_ROOM_CONFIG_CLASS (klass);
+
+ parent_class->update_async = idle_room_config_update_configuration_async;
+ g_type_class_add_private (klass, sizeof (IdleRoomConfigPrivate));
+}
+
+IdleRoomConfig *
+idle_room_config_new (
+ TpBaseChannel *channel)
+{
+ g_return_val_if_fail (TP_IS_BASE_CHANNEL (channel), NULL);
+
+ return g_object_new (IDLE_TYPE_ROOM_CONFIG,
+ "channel", channel,
+ NULL);
+}
+
+static void
+updated_configuration_cb (
+ GObject *source,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ IdleMUCChannel *channel = IDLE_MUC_CHANNEL (source);
+ GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data);
+ GError *error = NULL;
+
+ if (!idle_muc_channel_update_configuration_finish (channel, result, &error))
+ {
+ g_simple_async_result_set_from_error (simple, error);
+ g_clear_error (&error);
+ }
+
+ g_simple_async_result_complete (simple);
+ g_object_unref (simple);
+}
+
+static void
+idle_room_config_update_configuration_async (
+ TpBaseRoomConfig *base_config,
+ GHashTable *validated_properties,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ TpBaseChannel *base_channel = tp_base_room_config_dup_channel (base_config);
+ GSimpleAsyncResult *simple = g_simple_async_result_new (
+ G_OBJECT (base_config), callback, user_data,
+ idle_room_config_update_configuration_async);
+
+ idle_muc_channel_update_configuration_async (
+ IDLE_MUC_CHANNEL (base_channel), validated_properties,
+ updated_configuration_cb, simple);
+ g_object_unref (base_channel);
+}
diff --git a/src/room-config.h b/src/room-config.h
new file mode 100644
index 0000000..8d2eadb
--- /dev/null
+++ b/src/room-config.h
@@ -0,0 +1,61 @@
+/*
+ * room-config.h - header for Channel.I.RoomConfig1 implementation
+ * Copyright © 2011-2012 Collabora Ltd.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef IDLE_ROOM_CONFIG_H
+#define IDLE_ROOM_CONFIG_H
+
+#include <glib-object.h>
+#include <telepathy-glib/base-room-config.h>
+
+typedef struct _IdleRoomConfig IdleRoomConfig;
+typedef struct _IdleRoomConfigClass IdleRoomConfigClass;
+typedef struct _IdleRoomConfigPrivate IdleRoomConfigPrivate;
+
+struct _IdleRoomConfigClass {
+ TpBaseRoomConfigClass parent_class;
+};
+
+struct _IdleRoomConfig {
+ TpBaseRoomConfig parent;
+
+ IdleRoomConfigPrivate *priv;
+};
+
+IdleRoomConfig *idle_room_config_new (
+ TpBaseChannel *channel);
+
+/* TYPE MACROS */
+GType idle_room_config_get_type (void);
+
+#define IDLE_TYPE_ROOM_CONFIG \
+ (idle_room_config_get_type ())
+#define IDLE_ROOM_CONFIG(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST((obj), IDLE_TYPE_ROOM_CONFIG, IdleRoomConfig))
+#define IDLE_ROOM_CONFIG_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_CAST((klass), IDLE_TYPE_ROOM_CONFIG,\
+ IdleRoomConfigClass))
+#define IDLE_IS_ROOM_CONFIG(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE((obj), IDLE_TYPE_ROOM_CONFIG))
+#define IDLE_IS_ROOM_CONFIG_CLASS(klass) \
+ (G_TYPE_CHECK_CLASS_TYPE((klass), IDLE_TYPE_ROOM_CONFIG))
+#define IDLE_ROOM_CONFIG_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS ((obj), IDLE_TYPE_ROOM_CONFIG, \
+ IdleRoomConfigClass))
+
+#endif /* IDLE_ROOM_CONFIG_H */