diff options
author | Xavier Claessens <xclaesse@gmail.com> | 2007-05-31 14:34:41 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2007-05-31 14:34:41 +0800 |
commit | 6fe758a0d83f6872585a177a2e821d4105642308 (patch) | |
tree | 50d79a5ae475063c38e4e62cdaaa3c3817220077 /libempathy/gossip-chatroom.c | |
parent | a0c9dc2f22f510378063be5a8c872bfe8c92bd10 (diff) | |
download | gsoc2013-empathy-6fe758a0d83f6872585a177a2e821d4105642308.tar gsoc2013-empathy-6fe758a0d83f6872585a177a2e821d4105642308.tar.gz gsoc2013-empathy-6fe758a0d83f6872585a177a2e821d4105642308.tar.bz2 gsoc2013-empathy-6fe758a0d83f6872585a177a2e821d4105642308.tar.lz gsoc2013-empathy-6fe758a0d83f6872585a177a2e821d4105642308.tar.xz gsoc2013-empathy-6fe758a0d83f6872585a177a2e821d4105642308.tar.zst gsoc2013-empathy-6fe758a0d83f6872585a177a2e821d4105642308.zip |
Fix warning when selecting all accounts.
2007-05-31 Xavier Claessens <xclaesse@gmail.com>
* libempathy-gtk/gossip-account-chooser.c: Fix warning when selecting
all accounts.
* src/empathy-accounts-main.c:
* libempathy-gtk/empathy-status-icon.c:
* libempathy-gtk/gossip-accounts-dialog.h:
* libempathy-gtk/gossip-accounts-dialog.c:
* libempathy-gtk/gossip-preferences.h:
* libempathy-gtk/gossip-preferences.c: Set parent window.
* libempathy-gtk/empathy-main-window.c: Implement favorite chatroom
menu and fix a leak.
* libempathy-gtk/Makefile.am:
* libempathy/Makefile.am:
* libempathy/gossip-chatroom.c:
* libempathy/gossip-chatroom.h:
* libempathy/gossip-chatroom-manager.c:
* libempathy/gossip-chatroom-manager.h:
* libempathy/gossip-chatroom-manager.dtd:
* libempathy-gtk/gossip-chatrooms-window.glade:
* libempathy-gtk/gossip-chatrooms-window.c:
* libempathy-gtk/gossip-chatrooms-window.h: New files to implement
favorite chatrooms and a window to show them.
* libempathy-gtk/gossip-chat.c: Fix tooltip leaked.
* libempathy-gtk/gossip-chat-window.h:
* libempathy-gtk/gossip-chat-window.c: Do not use deprecated
gtk_object_sink(). Implement favorite chatroom features. Find a chat
by comparing the account AND the chat ID.
* src/empathy-chat-main.c:
* libempathy/empathy-tp-chat.h:
* libempathy/empathy-tp-chat.c:
* libempathy/gossip-utils.h:
* libempathy/gossip-utils.c: empathy_tp_chat_get_id() returns the Text
channel's name. The chat ID is unique only for a specified account.
* libempathy/empathy-tp-contact-list.c: Fix some leaks and add a FIXME
comment for a leak not yet fixed.
* TODO: Would be cool to have a glade catalog for libempathy-gtk.
svn path=/trunk/; revision=100
Diffstat (limited to 'libempathy/gossip-chatroom.c')
-rw-r--r-- | libempathy/gossip-chatroom.c | 360 |
1 files changed, 360 insertions, 0 deletions
diff --git a/libempathy/gossip-chatroom.c b/libempathy/gossip-chatroom.c new file mode 100644 index 000000000..eccd2824c --- /dev/null +++ b/libempathy/gossip-chatroom.c @@ -0,0 +1,360 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ +/* + * Copyright (C) 2007 Collabora Ltd. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program 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 + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Authors: Xavier Claessens <xclaesse@gmail.com> + */ + +#include "config.h" + +#include <string.h> + +#include <glib.h> + +#include "gossip-chatroom.h" +#include "gossip-utils.h" + +#define GET_PRIV(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GOSSIP_TYPE_CHATROOM, GossipChatroomPriv)) + +struct _GossipChatroomPriv { + McAccount *account; + gchar *room; + gchar *name; + gboolean auto_connect; +}; + +static void gossip_chatroom_class_init (GossipChatroomClass *klass); +static void gossip_chatroom_init (GossipChatroom *chatroom); +static void chatroom_finalize (GObject *object); +static void chatroom_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec); +static void chatroom_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec); + +enum { + PROP_0, + PROP_ACCOUNT, + PROP_ROOM, + PROP_NAME, + PROP_AUTO_CONNECT, +}; + +G_DEFINE_TYPE (GossipChatroom, gossip_chatroom, G_TYPE_OBJECT); + +static void +gossip_chatroom_class_init (GossipChatroomClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->finalize = chatroom_finalize; + object_class->get_property = chatroom_get_property; + object_class->set_property = chatroom_set_property; + + g_object_class_install_property (object_class, + PROP_ACCOUNT, + g_param_spec_object ("account", + "Chatroom Account", + "The account associated with an chatroom", + MC_TYPE_ACCOUNT, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_ROOM, + g_param_spec_string ("room", + "Chatroom Room", + "Chatroom represented as 'room@server'", + NULL, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_NAME, + g_param_spec_string ("name", + "Chatroom Name", + "Chatroom name", + NULL, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_AUTO_CONNECT, + g_param_spec_boolean ("auto_connect", + "Chatroom Auto Connect", + "Connect on startup", + FALSE, + G_PARAM_READWRITE)); + + + g_type_class_add_private (object_class, sizeof (GossipChatroomPriv)); +} + +static void +gossip_chatroom_init (GossipChatroom *chatroom) +{ +} + +static void +chatroom_finalize (GObject *object) +{ + GossipChatroomPriv *priv; + + priv = GET_PRIV (object); + + g_object_unref (priv->account); + g_free (priv->room); + g_free (priv->name); + + (G_OBJECT_CLASS (gossip_chatroom_parent_class)->finalize) (object); +} + +static void +chatroom_get_property (GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + GossipChatroomPriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) { + case PROP_ACCOUNT: + g_value_set_object (value, priv->account); + break; + case PROP_ROOM: + g_value_set_string (value, priv->room); + break; + case PROP_NAME: + g_value_set_string (value, priv->name); + break; + case PROP_AUTO_CONNECT: + g_value_set_boolean (value, priv->auto_connect); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +static void +chatroom_set_property (GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + GossipChatroomPriv *priv; + + priv = GET_PRIV (object); + + switch (param_id) { + case PROP_ACCOUNT: + gossip_chatroom_set_account (GOSSIP_CHATROOM (object), + g_value_get_object (value)); + break; + case PROP_ROOM: + gossip_chatroom_set_room (GOSSIP_CHATROOM (object), + g_value_get_string (value)); + break; + case PROP_NAME: + gossip_chatroom_set_name (GOSSIP_CHATROOM (object), + g_value_get_string (value)); + break; + case PROP_AUTO_CONNECT: + gossip_chatroom_set_auto_connect (GOSSIP_CHATROOM (object), + g_value_get_boolean (value)); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); + break; + }; +} + +GossipChatroom * +gossip_chatroom_new (McAccount *account, + const gchar *room) +{ + g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); + g_return_val_if_fail (room != NULL, NULL); + + return g_object_new (GOSSIP_TYPE_CHATROOM, + "account", account, + "room", room, + NULL); +} + +GossipChatroom * +gossip_chatroom_new_full (McAccount *account, + const gchar *room, + const gchar *name, + gboolean auto_connect) +{ + g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL); + g_return_val_if_fail (room != NULL, NULL); + + return g_object_new (GOSSIP_TYPE_CHATROOM, + "account", account, + "room", room, + "name", name, + "auto_connect", auto_connect, + NULL); +} + +McAccount * +gossip_chatroom_get_account (GossipChatroom *chatroom) +{ + GossipChatroomPriv *priv; + + g_return_val_if_fail (GOSSIP_IS_CHATROOM (chatroom), NULL); + + priv = GET_PRIV (chatroom); + return priv->account; +} + +void +gossip_chatroom_set_account (GossipChatroom *chatroom, + McAccount *account) +{ + GossipChatroomPriv *priv; + + g_return_if_fail (GOSSIP_IS_CHATROOM (chatroom)); + g_return_if_fail (MC_IS_ACCOUNT (account)); + + priv = GET_PRIV (chatroom); + + if (account == priv->account) { + return; + } + if (priv->account) { + g_object_unref (priv->account); + } + priv->account = g_object_ref (account); + + g_object_notify (G_OBJECT (chatroom), "account"); +} + +const gchar * +gossip_chatroom_get_room (GossipChatroom *chatroom) +{ + GossipChatroomPriv *priv; + + g_return_val_if_fail (GOSSIP_IS_CHATROOM (chatroom), NULL); + + priv = GET_PRIV (chatroom); + return priv->room; +} + +void +gossip_chatroom_set_room (GossipChatroom *chatroom, + const gchar *room) +{ + GossipChatroomPriv *priv; + + g_return_if_fail (GOSSIP_IS_CHATROOM (chatroom)); + g_return_if_fail (room != NULL); + + priv = GET_PRIV (chatroom); + + g_free (priv->room); + priv->room = g_strdup (room); + + g_object_notify (G_OBJECT (chatroom), "room"); +} + +const gchar * +gossip_chatroom_get_name (GossipChatroom *chatroom) +{ + GossipChatroomPriv *priv; + + g_return_val_if_fail (GOSSIP_IS_CHATROOM (chatroom), NULL); + + priv = GET_PRIV (chatroom); + + if (G_STR_EMPTY (priv->name)) { + return priv->room; + } + + return priv->name; +} + +void +gossip_chatroom_set_name (GossipChatroom *chatroom, + const gchar *name) +{ + GossipChatroomPriv *priv; + + g_return_if_fail (GOSSIP_IS_CHATROOM (chatroom)); + g_return_if_fail (name != NULL); + + priv = GET_PRIV (chatroom); + + g_free (priv->name); + priv->name = g_strdup (name); + + g_object_notify (G_OBJECT (chatroom), "name"); +} + +gboolean +gossip_chatroom_get_auto_connect (GossipChatroom *chatroom) +{ + GossipChatroomPriv *priv; + + g_return_val_if_fail (GOSSIP_IS_CHATROOM (chatroom), FALSE); + + priv = GET_PRIV (chatroom); + return priv->auto_connect; +} + +void +gossip_chatroom_set_auto_connect (GossipChatroom *chatroom, + gboolean auto_connect) +{ + GossipChatroomPriv *priv; + + g_return_if_fail (GOSSIP_IS_CHATROOM (chatroom)); + + priv = GET_PRIV (chatroom); + + priv->auto_connect = auto_connect; + + g_object_notify (G_OBJECT (chatroom), "auto-connect"); +} + +gboolean +gossip_chatroom_equal (gconstpointer v1, + gconstpointer v2) +{ + McAccount *account_a; + McAccount *account_b; + const gchar *room_a; + const gchar *room_b; + + g_return_val_if_fail (GOSSIP_IS_CHATROOM (v1), FALSE); + g_return_val_if_fail (GOSSIP_IS_CHATROOM (v2), FALSE); + + account_a = gossip_chatroom_get_account (GOSSIP_CHATROOM (v1)); + account_b = gossip_chatroom_get_account (GOSSIP_CHATROOM (v2)); + + room_a = gossip_chatroom_get_room (GOSSIP_CHATROOM (v1)); + room_b = gossip_chatroom_get_room (GOSSIP_CHATROOM (v2)); + + return gossip_account_equal (account_a, account_b) && g_str_equal (room_a, room_b); +} + + |