aboutsummaryrefslogtreecommitdiffstats
path: root/libempathy
diff options
context:
space:
mode:
authorGuillaume Desmottes <gdesmott@gnome.org>2008-01-06 19:16:48 +0800
committerGuillaume Desmottes <gdesmott@gnome.org>2008-01-06 19:16:48 +0800
commite1b201353c2fea2d9468750ea3a7ebbab437b3e1 (patch)
treeb5ff3e1dab6b7ac7b09173b70652715f922fea8b /libempathy
parentb958778c4e8971e0ffc4befb447c2acc8a9d047e (diff)
downloadgsoc2013-empathy-e1b201353c2fea2d9468750ea3a7ebbab437b3e1.tar
gsoc2013-empathy-e1b201353c2fea2d9468750ea3a7ebbab437b3e1.tar.gz
gsoc2013-empathy-e1b201353c2fea2d9468750ea3a7ebbab437b3e1.tar.bz2
gsoc2013-empathy-e1b201353c2fea2d9468750ea3a7ebbab437b3e1.tar.lz
gsoc2013-empathy-e1b201353c2fea2d9468750ea3a7ebbab437b3e1.tar.xz
gsoc2013-empathy-e1b201353c2fea2d9468750ea3a7ebbab437b3e1.tar.zst
gsoc2013-empathy-e1b201353c2fea2d9468750ea3a7ebbab437b3e1.zip
move empathy-irc-network-manager, empathy-irc-network and empathy-irc-server from libempathy-gtk to libempathy
Diffstat (limited to 'libempathy')
-rw-r--r--libempathy/empathy-irc-network-manager.c480
-rw-r--r--libempathy/empathy-irc-network-manager.h84
-rw-r--r--libempathy/empathy-irc-network.c196
-rw-r--r--libempathy/empathy-irc-network.h75
-rw-r--r--libempathy/empathy-irc-server.c187
-rw-r--r--libempathy/empathy-irc-server.h66
6 files changed, 1088 insertions, 0 deletions
diff --git a/libempathy/empathy-irc-network-manager.c b/libempathy/empathy-irc-network-manager.c
new file mode 100644
index 000000000..1c1cea9e2
--- /dev/null
+++ b/libempathy/empathy-irc-network-manager.c
@@ -0,0 +1,480 @@
+/*
+ * Copyright (C) 2004-2007 Guillaume Desmottes
+ *
+ * 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.
+ */
+
+#include <config.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
+
+#include <libempathy/empathy-debug.h>
+
+#include "empathy-irc-network-manager.h"
+
+#define IRC_NETWORKS_XML_FILENAME "irc-networks.xml"
+
+#define DEBUG_DOMAIN "IrcNetworkManager"
+
+G_DEFINE_TYPE (EmpathyIrcNetworkManager, empathy_irc_network_manager,
+ G_TYPE_OBJECT);
+
+/* properties */
+enum
+{
+ PROP_FILENAME = 1,
+ LAST_PROPERTY
+};
+
+typedef struct _EmpathyIrcNetworkManagerPrivate
+ EmpathyIrcNetworkManagerPrivate;
+
+struct _EmpathyIrcNetworkManagerPrivate {
+ GSList *irc_networks;
+
+ gchar *filename;
+};
+
+#define EMPATHY_IRC_NETWORK_MANAGER_GET_PRIVATE(obj)\
+ ((EmpathyIrcNetworkManagerPrivate *) obj->priv)
+
+static gboolean
+irc_network_manager_get_all (EmpathyIrcNetworkManager *manager);
+static gboolean
+irc_network_manager_file_parse (EmpathyIrcNetworkManager *manager,
+ const gchar *filename);
+static gboolean
+irc_network_manager_file_save (EmpathyIrcNetworkManager *manager);
+
+static void
+empathy_irc_network_manager_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyIrcNetworkManager *self = EMPATHY_IRC_NETWORK_MANAGER (object);
+ EmpathyIrcNetworkManagerPrivate *priv =
+ EMPATHY_IRC_NETWORK_MANAGER_GET_PRIVATE (self);
+
+ switch (property_id)
+ {
+ case PROP_FILENAME:
+ g_value_set_string (value, priv->filename);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+empathy_irc_network_manager_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyIrcNetworkManager *self = EMPATHY_IRC_NETWORK_MANAGER (object);
+ EmpathyIrcNetworkManagerPrivate *priv =
+ EMPATHY_IRC_NETWORK_MANAGER_GET_PRIVATE (self);
+
+ switch (property_id)
+ {
+ case PROP_FILENAME:
+ g_free (priv->filename);
+ priv->filename = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+static void
+empathy_irc_network_manager_finalize (GObject *object)
+{
+ EmpathyIrcNetworkManager *self = EMPATHY_IRC_NETWORK_MANAGER (object);
+ EmpathyIrcNetworkManagerPrivate *priv =
+ EMPATHY_IRC_NETWORK_MANAGER_GET_PRIVATE (self);
+
+ g_free (priv->filename);
+
+ g_slist_foreach (priv->irc_networks, (GFunc) g_object_unref, NULL);
+ g_slist_free (priv->irc_networks);
+
+ G_OBJECT_CLASS (empathy_irc_network_manager_parent_class)->finalize (object);
+}
+
+static void
+empathy_irc_network_manager_init (EmpathyIrcNetworkManager *self)
+{
+ EmpathyIrcNetworkManagerPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ EMPATHY_TYPE_IRC_NETWORK_MANAGER, EmpathyIrcNetworkManagerPrivate);
+
+ self->priv = priv;
+}
+
+static void
+empathy_irc_network_manager_class_init (EmpathyIrcNetworkManagerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GParamSpec *param_spec;
+
+ object_class->get_property = empathy_irc_network_manager_get_property;
+ object_class->set_property = empathy_irc_network_manager_set_property;
+
+ g_type_class_add_private (object_class,
+ sizeof (EmpathyIrcNetworkManagerPrivate));
+
+ object_class->finalize = empathy_irc_network_manager_finalize;
+
+ param_spec = g_param_spec_string (
+ "filename",
+ "Filename path",
+ "The path of the filename from which we have to load"
+ "the networks list",
+ "",
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB);
+ g_object_class_install_property (object_class, PROP_FILENAME, param_spec);
+}
+
+EmpathyIrcNetworkManager *
+empathy_irc_network_manager_new (void)
+{
+
+ EmpathyIrcNetworkManager *manager;
+
+ manager = g_object_new (EMPATHY_TYPE_IRC_NETWORK_MANAGER,
+ "filename", "/home/cassidy/.gnome2/Empathy/irc-networks.xml",
+ NULL);
+
+ /* load file */
+ // XXX move that in the constructor
+ irc_network_manager_get_all (manager);
+
+ return manager;
+}
+
+gboolean
+empathy_irc_network_manager_add (EmpathyIrcNetworkManager *self,
+ EmpathyIrcNetwork *irc_network)
+{
+ EmpathyIrcNetworkManagerPrivate *priv;
+
+ g_return_val_if_fail (EMPATHY_IS_IRC_NETWORK_MANAGER (self), FALSE);
+ g_return_val_if_fail (EMPATHY_IS_IRC_NETWORK (irc_network), FALSE);
+
+ 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));
+
+ g_signal_emit (manager, signals[IRC_NETWORK_ADDED], 0, irc_network);
+
+ return TRUE;
+ }
+ */
+
+ return FALSE;
+}
+
+void
+empathy_irc_network_manager_remove (EmpathyIrcNetworkManager *self,
+ EmpathyIrcNetwork *irc_network)
+{
+ EmpathyIrcNetworkManagerPrivate *priv;
+
+ g_return_if_fail (EMPATHY_IS_IRC_NETWORK_MANAGER (self));
+ g_return_if_fail (EMPATHY_IS_IRC_NETWORK (irc_network));
+
+ priv = EMPATHY_IRC_NETWORK_MANAGER_GET_PRIVATE (self);
+
+ /*
+ empathy_debug (DEBUG_DOMAIN,
+ "Removing irc_network with name:'%s'",
+ empathy_irc_network_get_name (irc_network));
+
+ priv->irc_networks = g_slist_remove (priv->irc_networks, irc_network);
+
+ g_object_unref (irc_network);
+ */
+}
+
+GSList *
+empathy_irc_network_manager_get_irc_networks (EmpathyIrcNetworkManager *self)
+{
+ EmpathyIrcNetworkManagerPrivate *priv;
+ GSList *irc_networks;
+
+ g_return_val_if_fail (EMPATHY_IS_IRC_NETWORK_MANAGER (self), NULL);
+
+ priv = EMPATHY_IRC_NETWORK_MANAGER_GET_PRIVATE (self);
+
+ irc_networks = g_slist_copy (priv->irc_networks);
+ g_slist_foreach (irc_networks, (GFunc)g_object_ref, NULL);
+
+ return irc_networks;
+}
+
+gboolean
+empathy_irc_network_manager_store (EmpathyIrcNetworkManager *self)
+{
+ g_return_val_if_fail (EMPATHY_IS_IRC_NETWORK_MANAGER (self), FALSE);
+
+ empathy_debug (DEBUG_DOMAIN, "Saving IRC networks");
+
+ return irc_network_manager_file_save (self);
+}
+
+/*
+ * API to save/load and parse the irc_networks file.
+ */
+
+static gboolean
+irc_network_manager_get_all (EmpathyIrcNetworkManager *self)
+{
+
+ EmpathyIrcNetworkManagerPrivate *priv;
+ gchar *dir;
+ gchar *file_with_path = NULL;
+
+ priv = EMPATHY_IRC_NETWORK_MANAGER_GET_PRIVATE (self);
+
+ if (!priv->filename)
+ {
+ dir = g_build_filename (g_get_home_dir (), ".gnome2", PACKAGE_NAME,
+ NULL);
+
+ if (!g_file_test (dir, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR))
+ {
+ g_mkdir_with_parents (dir, S_IRUSR | S_IWUSR | S_IXUSR);
+ }
+
+ file_with_path = g_build_filename (dir, IRC_NETWORKS_XML_FILENAME, NULL);
+ g_free (dir);
+ }
+ else
+ {
+ file_with_path = g_strdup (priv->filename);
+ }
+
+ /* read file in */
+ if (g_file_test (file_with_path, G_FILE_TEST_EXISTS) &&
+ !irc_network_manager_file_parse (self, file_with_path))
+ {
+ g_free (file_with_path);
+ return FALSE;
+ }
+
+ g_free (file_with_path);
+
+ return TRUE;
+}
+
+static void
+irc_network_manager_parse_irc_server (EmpathyIrcNetwork *network,
+ xmlNodePtr node)
+{
+ xmlNodePtr server_node;
+ gchar *str;
+
+ for (server_node = node->children; server_node;
+ server_node = server_node->next)
+ {
+ xmlNodePtr child;
+ gchar *address = NULL, *port = NULL, *ssl = NULL;
+
+ if (strcmp (server_node->name, "server") != 0)
+ continue;
+
+ for (child = server_node->children; child; child = child->next)
+ {
+ gchar *tag;
+ tag = (gchar *) child->name;
+ str = (gchar *) xmlNodeGetContent (child);
+
+ if (!str)
+ continue;
+
+ if (strcmp (tag, "address") == 0)
+ {
+ g_print ("server adr: %s\n", str);
+ address = str;
+ }
+
+ else if (strcmp (tag, "port") == 0)
+ {
+ g_print ("server port: %s\n", str);
+ port = str;
+ }
+
+ else if (strcmp (tag, "ssl") == 0)
+ {
+ g_print ("server ssl: %s\n", str);
+ ssl = str;
+ }
+ }
+
+ if (address != NULL && port != NULL && ssl != NULL)
+ {
+ gint port_nb;
+ gboolean have_ssl = FALSE;
+ EmpathyIrcServer *server;
+
+ port_nb = strtol (str, NULL, 10);
+ if (port_nb <= 0 || port_nb > 65556)
+ port_nb = 6667;
+
+ if (strcmp (ssl, "TRUE") == 0)
+ have_ssl = TRUE;
+
+ server = empathy_irc_server_new (address, port_nb, have_ssl);
+ empathy_irc_network_add_server (network, server);
+ }
+
+ if (address)
+ xmlFree (address);
+ if (port)
+ xmlFree (port);
+ if (ssl)
+ xmlFree (ssl);
+ }
+}
+
+static void
+irc_network_manager_parse_irc_network (EmpathyIrcNetworkManager *self,
+ xmlNodePtr node)
+{
+ EmpathyIrcNetwork *network;
+ xmlNodePtr child;
+ gchar *str;
+ gchar *id, *name;
+
+ if (!xmlHasProp (node, "id"))
+ return;
+
+ if (!xmlHasProp (node, "name"))
+ return;
+
+ id = xmlGetProp (node, "id");
+ name = xmlGetProp (node, "name");
+ g_print ("id: %s name %s\n", id, name);
+ network = empathy_irc_network_new (id, name);
+ xmlFree (id);
+
+ for (child = node->children; child; child = child->next)
+ {
+ gchar *tag;
+
+ tag = (gchar *) child->name;
+ str = (gchar *) xmlNodeGetContent (child);
+
+ if (!str)
+ continue;
+
+ if (strcmp (tag, "servers") == 0)
+ {
+ g_print ("servers\n");
+ irc_network_manager_parse_irc_server (network, child);
+ }
+
+ xmlFree (str);
+ }
+
+ empathy_irc_network_manager_add (self, network);
+
+ g_object_unref (network);
+}
+
+static gboolean
+irc_network_manager_file_parse (EmpathyIrcNetworkManager *self,
+ const gchar *filename)
+{
+ EmpathyIrcNetworkManagerPrivate *priv;
+ xmlParserCtxtPtr ctxt;
+ xmlDocPtr doc;
+ xmlNodePtr networks;
+ xmlNodePtr node;
+
+ priv = EMPATHY_IRC_NETWORK_MANAGER_GET_PRIVATE (self);
+
+ empathy_debug (DEBUG_DOMAIN,
+ "Attempting to parse file:'%s'...",
+ filename);
+
+ ctxt = xmlNewParserCtxt ();
+
+ /* Parse and validate the file. */
+ doc = xmlCtxtReadFile (ctxt, filename, NULL, 0);
+ if (!doc)
+ {
+ g_warning ("Failed to parse file:'%s'", filename);
+ xmlFreeParserCtxt (ctxt);
+ return FALSE;
+ }
+
+ /*
+ if (!empathy_xml_validate (doc, IRC_NETWORKS_DTD_FILENAME)) {
+ g_warning ("Failed to validate file:'%s'", filename);
+ xmlFreeDoc (doc);
+ xmlFreeParserCtxt (ctxt);
+ return FALSE;
+ }
+ */
+
+ /* The root node, networks. */
+ networks = xmlDocGetRootElement (doc);
+
+
+ for (node = networks->children; node; node = node->next)
+ {
+ irc_network_manager_parse_irc_network (self, node);
+ }
+
+ /*
+ empathy_debug (DEBUG_DOMAIN,
+ "Parsed %d irc_networks",
+ g_list_length (priv->irc_networks));
+
+ */
+
+ xmlFreeDoc(doc);
+ xmlFreeParserCtxt (ctxt);
+
+ return TRUE;
+}
+
+static gboolean
+irc_network_manager_file_save (EmpathyIrcNetworkManager *self)
+{
+ //TODO
+ return TRUE;
+}
diff --git a/libempathy/empathy-irc-network-manager.h b/libempathy/empathy-irc-network-manager.h
new file mode 100644
index 000000000..1148b570a
--- /dev/null
+++ b/libempathy/empathy-irc-network-manager.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2005-2007 Guillaume Desmottes
+ *
+ * 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.
+ */
+
+#ifndef __EMPATHY_IRC_NETWORK_MANAGER_H__
+#define __EMPATHY_IRC_NETWORK_MANAGER_H__
+
+#include <glib-object.h>
+
+#include "empathy-irc-network.h"
+
+G_BEGIN_DECLS
+
+typedef struct _EmpathyIrcNetworkManager EmpathyIrcNetworkManager;
+typedef struct _EmpathyIrcNetworkManagerClass EmpathyIrcNetworkManagerClass;
+
+struct _EmpathyIrcNetworkManager
+{
+ GObject parent;
+
+ gpointer priv;
+};
+
+struct _EmpathyIrcNetworkManagerClass
+{
+ GObjectClass parent_class;
+};
+
+GType
+empathy_irc_network_manager_get_type (void);
+
+/* TYPE MACROS */
+#define EMPATHY_TYPE_IRC_NETWORK_MANAGER \
+ (empathy_irc_network_manager_get_type ())
+#define EMPATHY_IRC_NETWORK_MANAGER(o) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_IRC_NETWORK_MANAGER, \
+ EmpathyIrcNetworkManager))
+#define EMPATHY_IRC_NETWORK_MANAGER_CLASS(k) \
+ (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_IRC_NETWORK_MANAGER, \
+ EmpathyIrcNetworkManagerClass))
+#define EMPATHY_IS_IRC_NETWORK_MANAGER(o) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_IRC_NETWORK_MANAGER))
+#define EMPATHY_IS_IRC_NETWORK_MANAGER_CLASS(k) \
+ (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_IRC_NETWORK_MANAGER))
+#define EMPATHY_IRC_NETWORK_MANAGER_GET_CLASS(o) \
+ (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_IRC_NETWORK_MANAGER, \
+ EmpathyIrcNetworkManagerClass))
+
+EmpathyIrcNetworkManager *
+empathy_irc_network_manager_new (void);
+
+gboolean
+empathy_irc_network_manager_add (EmpathyIrcNetworkManager *manager,
+ EmpathyIrcNetwork *irc_network);
+
+void
+empathy_irc_network_manager_remove (EmpathyIrcNetworkManager *manager,
+ EmpathyIrcNetwork *irc_network);
+
+GSList *
+empathy_irc_network_manager_get_irc_networks (
+ EmpathyIrcNetworkManager *manager);
+
+gboolean
+empathy_irc_network_manager_store (EmpathyIrcNetworkManager *manager);
+
+G_END_DECLS
+
+#endif /* __EMPATHY_IRC_NETWORK_MANAGER_H__ */
diff --git a/libempathy/empathy-irc-network.c b/libempathy/empathy-irc-network.c
new file mode 100644
index 000000000..94fb9831d
--- /dev/null
+++ b/libempathy/empathy-irc-network.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 2007 Guillaume Desmottes
+ *
+ * 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: Guillaume Desmottes <gdesmott@gnome.org>
+ */
+
+#include <config.h>
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "empathy-irc-network.h"
+
+G_DEFINE_TYPE (EmpathyIrcNetwork, empathy_irc_network, G_TYPE_OBJECT);
+
+/* properties */
+enum
+{
+ PROP_ID = 1,
+ PROP_NAME,
+ LAST_PROPERTY
+};
+
+typedef struct _EmpathyIrcNetworkPrivate EmpathyIrcNetworkPrivate;
+
+struct _EmpathyIrcNetworkPrivate
+{
+ gchar *id;
+ gchar *name;
+ GSList *servers;
+};
+
+#define EMPATHY_IRC_NETWORK_GET_PRIVATE(obj)\
+ ((EmpathyIrcNetworkPrivate *) obj->priv)
+
+static void
+empathy_irc_network_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyIrcNetwork *self = EMPATHY_IRC_NETWORK (object);
+ EmpathyIrcNetworkPrivate *priv = EMPATHY_IRC_NETWORK_GET_PRIVATE (self);
+
+ switch (property_id)
+ {
+ case PROP_ID:
+ g_value_set_string (value, priv->id);
+ break;
+ case PROP_NAME:
+ g_value_set_string (value, priv->name);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+empathy_irc_network_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyIrcNetwork *self = EMPATHY_IRC_NETWORK (object);
+ EmpathyIrcNetworkPrivate *priv = EMPATHY_IRC_NETWORK_GET_PRIVATE (self);
+
+ switch (property_id)
+ {
+ case PROP_ID:
+ g_free (priv->id);
+ priv->id = g_value_dup_string (value);
+ break;
+ case PROP_NAME:
+ g_free (priv->name);
+ priv->name = g_value_dup_string (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+empathy_irc_network_finalize (GObject *object)
+{
+ EmpathyIrcNetwork *self = EMPATHY_IRC_NETWORK (object);
+ EmpathyIrcNetworkPrivate *priv = EMPATHY_IRC_NETWORK_GET_PRIVATE (self);
+
+ g_free (priv->id);
+ g_free (priv->name);
+
+ G_OBJECT_CLASS (empathy_irc_network_parent_class)->finalize (object);
+}
+
+static void
+empathy_irc_network_init (EmpathyIrcNetwork *self)
+{
+ EmpathyIrcNetworkPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ EMPATHY_TYPE_IRC_NETWORK, EmpathyIrcNetworkPrivate);
+
+ self->priv = priv;
+
+ priv->servers = NULL;
+}
+
+static void
+empathy_irc_network_class_init (EmpathyIrcNetworkClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GParamSpec *param_spec;
+
+ object_class->get_property = empathy_irc_network_get_property;
+ object_class->set_property = empathy_irc_network_set_property;
+
+ g_type_class_add_private (object_class,
+ sizeof (EmpathyIrcNetworkPrivate));
+
+ object_class->finalize = empathy_irc_network_finalize;
+
+ param_spec = g_param_spec_string (
+ "id",
+ "Identifier",
+ "The unique identifier of this network",
+ "",
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB);
+ g_object_class_install_property (object_class, PROP_ID, param_spec);
+
+ param_spec = g_param_spec_string (
+ "name",
+ "Network name",
+ "The displayed name of this network",
+ "",
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB);
+ g_object_class_install_property (object_class, PROP_NAME, param_spec);
+
+}
+
+EmpathyIrcNetwork *
+empathy_irc_network_new (const gchar *id,
+ const gchar *name)
+{
+ return g_object_new (EMPATHY_TYPE_IRC_NETWORK,
+ "id", id,
+ "name", name,
+ NULL);
+}
+
+const GSList *
+empathy_irc_network_get_servers (EmpathyIrcNetwork *self)
+{
+ EmpathyIrcNetworkPrivate *priv;
+
+ g_return_val_if_fail (EMPATHY_IS_IRC_NETWORK (self), NULL);
+ priv = EMPATHY_IRC_NETWORK_GET_PRIVATE (self);
+
+ return priv->servers;
+}
+
+void
+empathy_irc_network_add_server (EmpathyIrcNetwork *self,
+ EmpathyIrcServer *server)
+{
+ EmpathyIrcNetworkPrivate *priv;
+
+ g_return_if_fail (EMPATHY_IS_IRC_NETWORK (self));
+ g_return_if_fail (server != NULL && EMPATHY_IS_IRC_SERVER (server));
+
+ priv = EMPATHY_IRC_NETWORK_GET_PRIVATE (self);
+
+ priv->servers = g_slist_append (priv->servers, server);
+}
diff --git a/libempathy/empathy-irc-network.h b/libempathy/empathy-irc-network.h
new file mode 100644
index 000000000..2abaa8b21
--- /dev/null
+++ b/libempathy/empathy-irc-network.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2007 Guillaume Desmottes
+ *
+ * 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: Guillaume Desmottes <gdesmott@gnome.org>
+ */
+
+#ifndef __EMPATHY_IRC_NETWORK_H__
+#define __EMPATHY_IRC_NETWORK_H__
+
+#include <glib-object.h>
+
+#include "empathy-irc-server.h"
+
+G_BEGIN_DECLS
+
+typedef struct _EmpathyIrcNetwork EmpathyIrcNetwork;
+typedef struct _EmpathyIrcNetworkClass EmpathyIrcNetworkClass;
+
+struct _EmpathyIrcNetwork
+{
+ GObject parent;
+
+ gpointer priv;
+};
+
+struct _EmpathyIrcNetworkClass
+{
+ GObjectClass parent_class;
+};
+
+GType empathy_irc_network_get_type (void);
+
+/* TYPE MACROS */
+#define EMPATHY_TYPE_IRC_NETWORK (empathy_irc_network_get_type ())
+#define EMPATHY_IRC_NETWORK(o) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_IRC_NETWORK, \
+ EmpathyIrcNetwork))
+#define EMPATHY_IRC_NETWORK_CLASS(k) \
+ (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_IRC_NETWORK,\
+ EmpathyIrcNetworkClass))
+#define EMPATHY_IS_IRC_NETWORK(o) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_IRC_NETWORK))
+#define EMPATHY_IS_IRC_NETWORK_CLASS(k) \
+ (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_IRC_NETWORK))
+#define EMPATHY_IRC_NETWORK_GET_CLASS(o) \
+ (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_IRC_NETWORK, \
+ EmpathyIrcNetworkClass))
+
+EmpathyIrcNetwork *
+empathy_irc_network_new (const gchar *id, const gchar *name);
+
+const GSList *
+empathy_irc_network_get_servers (EmpathyIrcNetwork *network);
+
+void empathy_irc_network_add_server (EmpathyIrcNetwork *network,
+ EmpathyIrcServer *server);
+
+G_END_DECLS
+
+#endif /* __EMPATHY_IRC_NETWORK_H__ */
diff --git a/libempathy/empathy-irc-server.c b/libempathy/empathy-irc-server.c
new file mode 100644
index 000000000..7b74c0fa3
--- /dev/null
+++ b/libempathy/empathy-irc-server.c
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2007 Guillaume Desmottes
+ *
+ * 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: Guillaume Desmottes <gdesmott@gnome.org>
+ */
+
+#include <config.h>
+#include <string.h>
+#include <stdlib.h>
+#include <glib.h>
+#include <glib/gi18n.h>
+
+#include "empathy-irc-server.h"
+
+G_DEFINE_TYPE (EmpathyIrcServer, empathy_irc_server, G_TYPE_OBJECT);
+
+/* properties */
+enum
+{
+ PROP_ADDRESS = 1,
+ PROP_PORT,
+ PROP_SSL,
+ LAST_PROPERTY
+};
+
+typedef struct _EmpathyIrcServerPrivate EmpathyIrcServerPrivate;
+
+struct _EmpathyIrcServerPrivate
+{
+ gchar *address;
+ gint port;
+ gboolean ssl;
+};
+
+#define EMPATHY_IRC_SERVER_GET_PRIVATE(obj)\
+ ((EmpathyIrcServerPrivate *) obj->priv)
+
+static void
+empathy_irc_server_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
+ EmpathyIrcServerPrivate *priv = EMPATHY_IRC_SERVER_GET_PRIVATE (self);
+
+ switch (property_id)
+ {
+ case PROP_ADDRESS:
+ g_value_set_string (value, priv->address);
+ break;
+ case PROP_PORT:
+ g_value_set_uint (value, priv->port);
+ break;
+ case PROP_SSL:
+ g_value_set_boolean (value, priv->ssl);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+empathy_irc_server_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
+ EmpathyIrcServerPrivate *priv = EMPATHY_IRC_SERVER_GET_PRIVATE (self);
+
+ switch (property_id)
+ {
+ case PROP_ADDRESS:
+ g_free (priv->address);
+ priv->address = g_value_dup_string (value);
+ break;
+ case PROP_PORT:
+ priv->port = g_value_get_uint (value);
+ break;
+ case PROP_SSL:
+ priv->ssl = g_value_get_boolean (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+static void
+empathy_irc_server_finalize (GObject *object)
+{
+ EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
+ EmpathyIrcServerPrivate *priv = EMPATHY_IRC_SERVER_GET_PRIVATE (self);
+
+ g_free (priv->address);
+
+ G_OBJECT_CLASS (empathy_irc_server_parent_class)->finalize (object);
+}
+
+static void
+empathy_irc_server_init (EmpathyIrcServer *self)
+{
+ EmpathyIrcServerPrivate *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ EMPATHY_TYPE_IRC_SERVER, EmpathyIrcServerPrivate);
+
+ self->priv = priv;
+}
+
+static void
+empathy_irc_server_class_init (EmpathyIrcServerClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GParamSpec *param_spec;
+
+ object_class->get_property = empathy_irc_server_get_property;
+ object_class->set_property = empathy_irc_server_set_property;
+
+ g_type_class_add_private (object_class,
+ sizeof (EmpathyIrcServerPrivate));
+
+ object_class->finalize = empathy_irc_server_finalize;
+
+ param_spec = g_param_spec_string (
+ "address",
+ "Server address",
+ "The address of this server",
+ "",
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB);
+ g_object_class_install_property (object_class, PROP_ADDRESS, param_spec);
+
+ param_spec = g_param_spec_uint (
+ "port",
+ "Server port",
+ "The port to use to connect on this server",
+ 0, G_MAXUINT16, 6667,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB);
+ g_object_class_install_property (object_class, PROP_PORT, param_spec);
+
+ param_spec = g_param_spec_boolean (
+ "ssl",
+ "SSL",
+ "If this server needs SSL connection",
+ FALSE,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_NICK |
+ G_PARAM_STATIC_BLURB);
+ g_object_class_install_property (object_class, PROP_SSL, param_spec);
+}
+
+EmpathyIrcServer *
+empathy_irc_server_new (const gchar *address,
+ guint port,
+ gboolean ssl)
+{
+ return g_object_new (EMPATHY_TYPE_IRC_SERVER,
+ "address", address,
+ "port", port,
+ "ssl", ssl,
+ NULL);
+}
diff --git a/libempathy/empathy-irc-server.h b/libempathy/empathy-irc-server.h
new file mode 100644
index 000000000..5982a6b6b
--- /dev/null
+++ b/libempathy/empathy-irc-server.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2007 Guillaume Desmottes
+ *
+ * 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: Guillaume Desmottes <gdesmott@gnome.org>
+ */
+
+#ifndef __EMPATHY_IRC_SERVER_H__
+#define __EMPATHY_IRC_SERVER_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+typedef struct _EmpathyIrcServer EmpathyIrcServer;
+typedef struct _EmpathyIrcServerClass EmpathyIrcServerClass;
+
+struct _EmpathyIrcServer
+{
+ GObject parent;
+
+ gpointer priv;
+};
+
+struct _EmpathyIrcServerClass
+{
+ GObjectClass parent_class;
+};
+
+GType empathy_irc_server_get_type (void);
+
+/* TYPE MACROS */
+#define EMPATHY_TYPE_IRC_SERVER (empathy_irc_server_get_type ())
+#define EMPATHY_IRC_SERVER(o) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((o), EMPATHY_TYPE_IRC_SERVER, EmpathyIrcServer))
+#define EMPATHY_IRC_SERVER_CLASS(k) \
+ (G_TYPE_CHECK_CLASS_CAST ((k), EMPATHY_TYPE_IRC_SERVER, \
+ EmpathyIrcServerClass))
+#define EMPATHY_IS_IRC_SERVER(o) \
+ (G_TYPE_CHECK_INSTANCE_TYPE ((o), EMPATHY_TYPE_IRC_SERVER))
+#define EMPATHY_IS_IRC_SERVER_CLASS(k) \
+ (G_TYPE_CHECK_CLASS_TYPE ((k), EMPATHY_TYPE_IRC_SERVER))
+#define EMPATHY_IRC_SERVER_GET_CLASS(o) \
+ (G_TYPE_INSTANCE_GET_CLASS ((o), EMPATHY_TYPE_IRC_SERVER,\
+ EmpathyIrcServerClass))
+
+EmpathyIrcServer *
+empathy_irc_server_new (const gchar *address, guint port, gboolean ssl);
+
+G_END_DECLS
+
+#endif /* __EMPATHY_IRC_SERVER_H__ */