aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorGuillaume Desmottes <gdesmott@gnome.org>2008-01-09 07:12:55 +0800
committerGuillaume Desmottes <gdesmott@gnome.org>2008-01-09 07:12:55 +0800
commitfa6a77e797e30d14a41503ae579b9838dc4a29d3 (patch)
tree1d0c6cb39a94c5c6d69697eb6c0e9b5fc57054f8 /libempathy
parent4ac452a8e0add3ed1fa9c6fc3ee1e7084e59a7b9 (diff)
downloadgsoc2013-empathy-fa6a77e797e30d14a41503ae579b9838dc4a29d3.tar
gsoc2013-empathy-fa6a77e797e30d14a41503ae579b9838dc4a29d3.tar.gz
gsoc2013-empathy-fa6a77e797e30d14a41503ae579b9838dc4a29d3.tar.bz2
gsoc2013-empathy-fa6a77e797e30d14a41503ae579b9838dc4a29d3.tar.lz
gsoc2013-empathy-fa6a77e797e30d14a41503ae579b9838dc4a29d3.tar.xz
gsoc2013-empathy-fa6a77e797e30d14a41503ae579b9838dc4a29d3.tar.zst
gsoc2013-empathy-fa6a77e797e30d14a41503ae579b9838dc4a29d3.zip
properly implement empathy_irc_network_manager_add
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-irc-network-manager.c51
-rw-r--r--libempathy/empathy-irc-network-manager.h2
2 files changed, 28 insertions, 25 deletions
diff --git a/libempathy/empathy-irc-network-manager.c b/libempathy/empathy-irc-network-manager.c
index eaea4f048..1b6582d1b 100644
--- a/libempathy/empathy-irc-network-manager.c
+++ b/libempathy/empathy-irc-network-manager.c
@@ -225,40 +225,43 @@ add_network (EmpathyIrcNetworkManager *self,
g_hash_table_insert (priv->networks, g_strdup (id), g_object_ref (network));
}
-gboolean
+void
empathy_irc_network_manager_add (EmpathyIrcNetworkManager *self,
EmpathyIrcNetwork *network)
{
EmpathyIrcNetworkManagerPrivate *priv;
+ gchar *id, *bare_id, *tmp;
+ guint no = 0;
- g_return_val_if_fail (EMPATHY_IS_IRC_NETWORK_MANAGER (self), FALSE);
- g_return_val_if_fail (EMPATHY_IS_IRC_NETWORK (network), FALSE);
+ g_return_if_fail (EMPATHY_IS_IRC_NETWORK_MANAGER (self));
+ g_return_if_fail (EMPATHY_IS_IRC_NETWORK (network));
priv = EMPATHY_IRC_NETWORK_MANAGER_GET_PRIVATE (self);
- /* Don't add more than once */
- /*
- if (!empathy_irc_network_manager_find (manager, empathy_irc_network_get_name (irc_network))) {
- const gchar *name;
-
- name = empathy_irc_network_get_name (irc_network);
-
- empathy_debug (DEBUG_DOMAIN, "Adding %s irc_network with name:'%s'",
- empathy_irc_network_type_to_string (type),
- name);
-
- priv->irc_networks = g_list_append (priv->irc_networks, g_object_ref (irc_network));
+ /* generate an id for this network */
+ g_object_get (network, "name", &tmp, NULL);
+ bare_id = g_ascii_strdown (tmp, strlen (tmp));
+ id = g_strdup (bare_id);
+ g_free (tmp);
+ while (g_hash_table_lookup (priv->networks, id) != NULL && no < G_MAXUINT)
+ {
+ g_free (id);
+ id = g_strdup_printf ("%s%u", bare_id, no++);
+ }
- g_signal_emit (manager, signals[IRC_NETWORK_ADDED], 0, irc_network);
+ if (no == G_MAXUINT)
+ {
+ empathy_debug (DEBUG_DOMAIN,
+ "Can't add network: too many networks using a similiar ID");
+ return;
+ }
- return TRUE;
- }
- */
+ empathy_debug (DEBUG_DOMAIN, "add server with \"%s\" as ID", id);
- /* TODO: generate an id */
- add_network (self, network, "foo");
+ add_network (self, network, id);
- return FALSE;
+ g_free (bare_id);
+ g_free (id);
}
void
@@ -385,8 +388,8 @@ irc_network_manager_parse_irc_server (EmpathyIrcNetwork *network,
if (ssl == NULL || strcmp (ssl, "TRUE") == 0)
have_ssl = TRUE;
- empathy_debug (DEBUG_DOMAIN, "add server %s port %d ssl %d", address,
- port_nb, have_ssl);
+ empathy_debug (DEBUG_DOMAIN, "parsed server %s port %d ssl %d",
+ address, port_nb, have_ssl);
server = empathy_irc_server_new (address, port_nb, have_ssl);
empathy_irc_network_add_server (network, server);
diff --git a/libempathy/empathy-irc-network-manager.h b/libempathy/empathy-irc-network-manager.h
index c133c468a..4e7ff2ffb 100644
--- a/libempathy/empathy-irc-network-manager.h
+++ b/libempathy/empathy-irc-network-manager.h
@@ -65,7 +65,7 @@ EmpathyIrcNetworkManager *
empathy_irc_network_manager_new (const gchar *global_file,
const gchar *user_file);
-gboolean
+void
empathy_irc_network_manager_add (EmpathyIrcNetworkManager *manager,
EmpathyIrcNetwork *irc_network);