diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-05-15 11:17:41 +0100 |
---|---|---|
committer | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2012-05-15 11:17:41 +0100 |
commit | d342dfbab2e8a39f64d9c5d792a4a8fa96eef6cf (patch) | |
tree | 1c6bc039c191e056f84401759014471bc5c2217c | |
parent | 65ab1d0ec73dcf83533284ec157b255023edaee1 (diff) |
muc-channel: remove SetProperties implementation
Woo, getting closer!
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
-rw-r--r-- | src/idle-muc-channel.c | 269 |
1 files changed, 0 insertions, 269 deletions
diff --git a/src/idle-muc-channel.c b/src/idle-muc-channel.c index bd3029e..049814b 100644 --- a/src/idle-muc-channel.c +++ b/src/idle-muc-channel.c @@ -185,12 +185,6 @@ static void _free_flags_struct(gpointer data, gpointer user_data) g_boxed_free(TP_STRUCT_TYPE_PROPERTY_FLAGS_CHANGE, data); } -static void _free_prop_info_struct(gpointer data, gpointer user_data) -{ - g_boxed_free(TP_STRUCT_TYPE_PROPERTY_SPEC, data); -} - - static gboolean add_member(GObject *gobj, TpHandle handle, const gchar *message, GError **error); static gboolean remove_member(GObject *gobj, TpHandle handle, const gchar *message, GError **error); @@ -1784,260 +1778,6 @@ idle_muc_channel_send (GObject *obj, TpMessage *message, TpMessageSendingFlags f idle_text_send(obj, message, flags, priv->channel_name, IDLE_CONNECTION (base_conn)); } -static char to_irc_mode(IdleMUCChannelTPProperty prop_id) { - switch (prop_id) { - case TP_PROPERTY_INVITE_ONLY: - return 'i'; - case TP_PROPERTY_MODERATED: - return 'm'; - case TP_PROPERTY_PRIVATE: - return 's'; - default: - return '\0'; - } -} - -static int prop_arr_find(const GPtrArray *props, IdleMUCChannelTPProperty needle) { - for (guint i = 0; i < props->len; i++) { - GValue prop = {0, }; - guint prop_id; - - g_value_init(&prop, TP_STRUCT_TYPE_PROPERTY_VALUE); - g_value_set_static_boxed(&prop, g_ptr_array_index(props, i)); - - dbus_g_type_struct_get(&prop, - 0, &prop_id, - G_MAXUINT); - - if (prop_id == needle) { - return i; - } - } - - return -1; -} - -static void send_properties_request(IdleMUCChannel *obj, const GPtrArray *properties) { - IdleMUCChannelPrivate *priv; - GPtrArray *waiting; - gchar cmd[IRC_MSG_MAXLEN + 2]; - size_t len; - gchar *body; - - g_assert(obj != NULL); - g_assert(IDLE_IS_MUC_CHANNEL(obj)); - g_assert(properties != NULL); - - priv = obj->priv; - - waiting = g_ptr_array_new(); - - g_snprintf(cmd, IRC_MSG_MAXLEN + 2, "MODE %s ", priv->channel_name); - len = strlen(cmd); - body = cmd + len; - - for (guint i = 0; i < properties->len; i++) { - GValue prop = {0, }; - IdleMUCChannelTPProperty prop_id; - GValue *prop_val; - char irc_mode; - - g_value_init(&prop, TP_STRUCT_TYPE_PROPERTY_VALUE); - g_value_set_static_boxed(&prop, g_ptr_array_index(properties, i)); - - dbus_g_type_struct_get(&prop, - 0, &prop_id, - 1, &prop_val, - G_MAXUINT); - - irc_mode = to_irc_mode(prop_id); - - if (irc_mode != '\0') { - g_assert(G_VALUE_TYPE(prop_val) == G_TYPE_BOOLEAN); - - gboolean state = g_value_get_boolean(prop_val); - - size_t seq = 0; - - body[seq++] = state ? '+' : '-'; - - body[seq++] = irc_mode; - body[seq++] = '\0'; - - send_command (obj, cmd); - } else { - g_ptr_array_add(waiting, g_value_get_boxed(&prop)); - } - } - - if (waiting->len) { - int i, j; - gpointer tmp; - - i = prop_arr_find(waiting, TP_PROPERTY_LIMITED); - j = prop_arr_find(waiting, TP_PROPERTY_LIMIT); - - if ((i != -1) && (j != -1) && (i < j)) { - IDLE_DEBUG("swapping order of TP_PROPERTY_LIMIT and TP_PROPERTY_LIMITED"); - - tmp = g_ptr_array_index(waiting, i); - g_ptr_array_index(waiting, i) = g_ptr_array_index(waiting, j); - g_ptr_array_index(waiting, j) = tmp; - } - - i = prop_arr_find(waiting, TP_PROPERTY_PASSWORD_REQUIRED); - j = prop_arr_find(waiting, TP_PROPERTY_PASSWORD); - - if ((i != -1) && (j != -1) && (i < j)) { - IDLE_DEBUG("swapping order of TP_PROPERTY_PASSWORD and TP_PROPERTY_PASSWORD_REQUIRED"); - - tmp = g_ptr_array_index(waiting, i); - g_ptr_array_index(waiting, i) = g_ptr_array_index(waiting, j); - g_ptr_array_index(waiting, j) = tmp; - } - } - - /* okay now the data is ALWAYS before the boolean */ - - for (guint i = 0; i < waiting->len; i++) { - GValue prop = {0, }; - IdleMUCChannelTPProperty prop_id; - GValue *prop_val; - - g_value_init(&prop, TP_STRUCT_TYPE_PROPERTY_VALUE); - g_value_set_static_boxed(&prop, g_ptr_array_index(waiting, i)); - - dbus_g_type_struct_get(&prop, - 0, &prop_id, - 1, &prop_val, - G_MAXUINT); - - g_assert(prop_id < LAST_TP_PROPERTY_ENUM); - - if (prop_id == TP_PROPERTY_LIMIT || prop_id == TP_PROPERTY_PASSWORD) { - int j; - - g_value_copy(prop_val, priv->properties[prop_id].value); - - j = prop_arr_find(waiting, prop_id + 1); - - if (j == -1) { - if (prop_id == TP_PROPERTY_LIMIT && priv->mode_state.flags & MODE_FLAG_USER_LIMIT) - g_snprintf(body, IRC_MSG_MAXLEN - len, "+l %u", g_value_get_uint(prop_val)); - else if (prop_id == TP_PROPERTY_PASSWORD && priv->mode_state.flags & MODE_FLAG_KEY) - g_snprintf(body, IRC_MSG_MAXLEN - len, "+k %s", g_value_get_string(prop_val)); - else - IDLE_DEBUG("%u", __LINE__); - } - } else if (prop_id == TP_PROPERTY_LIMITED) { - guint limit = g_value_get_uint(priv->properties[TP_PROPERTY_LIMIT].value); - - if (g_value_get_boolean(prop_val)) { - if (limit != 0) - g_snprintf(body, IRC_MSG_MAXLEN - len, "+l %u", limit); - } else { - g_snprintf(body, IRC_MSG_MAXLEN - len, "-l"); - } - } else if (prop_id == TP_PROPERTY_PASSWORD_REQUIRED) { - const gchar *key = g_value_get_string(priv->properties[TP_PROPERTY_PASSWORD].value); - - if (g_value_get_boolean(prop_val)) { - if (key != NULL) - g_snprintf(body, IRC_MSG_MAXLEN - len, "+k %s", key); - } else { - g_snprintf(body, IRC_MSG_MAXLEN - len, "-k"); - } - } - - send_command (obj, cmd); - } - - g_ptr_array_free(waiting, TRUE); -} - -/** - * idle_muc_channel_set_properties - * - * Implements DBus method SetProperties - * on interface org.freedesktop.Telepathy.Properties - * - * @error: Used to return a pointer to a GError detailing any error - * that occured, DBus will throw the error only if this - * function returns false. - * - * Returns: TRUE if successful, FALSE if an error was thrown. - */ -static void idle_muc_channel_set_properties (TpSvcPropertiesInterface *iface, const GPtrArray * properties, DBusGMethodInvocation *context) { - IdleMUCChannel *obj = IDLE_MUC_CHANNEL(iface); - IdleMUCChannelPrivate *priv; - GPtrArray *to_change; - GError *error; - - g_assert(obj != NULL); - g_assert(IDLE_IS_MUC_CHANNEL(obj)); - - priv = obj->priv; - - to_change = g_ptr_array_new(); - - for (guint i = 0; i < properties->len; i++) { - GValue prop = {0, }; - IdleMUCChannelTPProperty prop_id; - GValue *prop_val; - - g_value_init(&prop, TP_STRUCT_TYPE_PROPERTY_VALUE); - g_value_set_static_boxed(&prop, g_ptr_array_index(properties, i)); - - dbus_g_type_struct_get(&prop, - 0, &prop_id, - 1, &prop_val, - G_MAXUINT); - - if (prop_id >= LAST_TP_PROPERTY_ENUM) { - IDLE_DEBUG("invalid property id %u", prop_id); - - error = g_error_new(TP_ERROR, TP_ERROR_INVALID_ARGUMENT, "invalid property id %u", prop_id); - dbus_g_method_return_error(context, error); - g_error_free(error); - g_ptr_array_free(to_change, TRUE); - - return; - } - - if ((priv->properties[prop_id].flags & TP_PROPERTY_FLAG_WRITE) == 0) { - IDLE_DEBUG("not allowed to set property with id %u", prop_id); - - error = g_error_new(TP_ERROR, TP_ERROR_PERMISSION_DENIED, "not allowed to set property with id %u", prop_id); - dbus_g_method_return_error(context, error); - g_error_free(error); - g_ptr_array_free(to_change, TRUE); - - return; - } - - if (!g_value_type_compatible(G_VALUE_TYPE(prop_val), property_signatures[prop_id].type)) { - IDLE_DEBUG("incompatible value type %s for prop_id %u", g_type_name(G_VALUE_TYPE(prop_val)), prop_id); - - error = g_error_new(TP_ERROR, TP_ERROR_INVALID_ARGUMENT, "incompatible value type %s for prop_id %u", g_type_name(G_VALUE_TYPE(prop_val)), prop_id); - dbus_g_method_return_error(context, error); - g_error_free(error); - g_ptr_array_free(to_change, TRUE); - - return; - } - - if (!g_value_compare(prop_val, priv->properties[prop_id].value)) { - g_ptr_array_add(to_change, g_value_get_boxed(&prop)); - } - } - - send_properties_request(obj, to_change); - - g_ptr_array_free(to_change, TRUE); - - tp_svc_properties_interface_return_from_set_properties(context); -} - static void idle_muc_channel_set_subject ( TpSvcChannelInterfaceSubject *iface, @@ -2129,12 +1869,6 @@ static void _password_iface_init(gpointer g_iface, gpointer iface_data) { #undef IMPLEMENT } -static void _properties_iface_init(gpointer g_iface, gpointer iface_data) { -#define IMPLEMENT(x) (void) idle_muc_channel_##x - IMPLEMENT(set_properties); -#undef IMPLEMENT -} - static void subject_iface_init ( gpointer g_iface, @@ -2146,9 +1880,6 @@ subject_iface_init ( tp_svc_channel_interface_subject_implement_##x (klass, idle_muc_channel_##x) IMPLEMENT (set_subject); #undef IMPLEMENT - - /* TODO: remove this, it's just to squash unusedness warnings. */ - _properties_iface_init (NULL, NULL); } void |