rename text/{persona,individual}-id as they are not standard
[empathy-mirror.git] / libempathy / empathy-irc-server.c
blob41da5385ee1253ac008633e2fa9cfea425b4bf24
1 /*
2 * Copyright (C) 2007-2008 Guillaume Desmottes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 * Authors: Guillaume Desmottes <gdesmott@gnome.org>
21 #include <config.h>
22 #include <string.h>
23 #include <stdlib.h>
24 #include <glib.h>
25 #include <glib/gi18n-lib.h>
27 #include <telepathy-glib/util.h>
29 #include "empathy-marshal.h"
30 #include "empathy-irc-server.h"
31 #include "empathy-utils.h"
33 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIrcServer)
34 typedef struct
36 gchar *address;
37 guint port;
38 gboolean ssl;
39 } EmpathyIrcServerPriv;
41 /* properties */
42 enum
44 PROP_ADDRESS = 1,
45 PROP_PORT,
46 PROP_SSL,
47 LAST_PROPERTY
50 /* signals */
51 enum
53 MODIFIED,
54 LAST_SIGNAL
57 static guint signals[LAST_SIGNAL] = {0};
59 G_DEFINE_TYPE (EmpathyIrcServer, empathy_irc_server, G_TYPE_OBJECT);
61 static void
62 empathy_irc_server_get_property (GObject *object,
63 guint property_id,
64 GValue *value,
65 GParamSpec *pspec)
67 EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
68 EmpathyIrcServerPriv *priv = GET_PRIV (self);
70 switch (property_id)
72 case PROP_ADDRESS:
73 g_value_set_string (value, priv->address);
74 break;
75 case PROP_PORT:
76 g_value_set_uint (value, priv->port);
77 break;
78 case PROP_SSL:
79 g_value_set_boolean (value, priv->ssl);
80 break;
81 default:
82 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
83 break;
87 static void
88 empathy_irc_server_set_property (GObject *object,
89 guint property_id,
90 const GValue *value,
91 GParamSpec *pspec)
93 EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
94 EmpathyIrcServerPriv *priv = GET_PRIV (self);
96 switch (property_id)
98 case PROP_ADDRESS:
99 if (tp_strdiff (priv->address, g_value_get_string (value)))
101 g_free (priv->address);
102 priv->address = g_value_dup_string (value);
103 g_signal_emit (object, signals[MODIFIED], 0);
105 break;
106 case PROP_PORT:
107 if (priv->port != g_value_get_uint (value))
109 priv->port = g_value_get_uint (value);
110 g_signal_emit (object, signals[MODIFIED], 0);
112 break;
113 case PROP_SSL:
114 if (priv->ssl != g_value_get_boolean (value))
116 priv->ssl = g_value_get_boolean (value);
117 g_signal_emit (object, signals[MODIFIED], 0);
119 break;
120 default:
121 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
122 break;
126 static void
127 empathy_irc_server_finalize (GObject *object)
129 EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
130 EmpathyIrcServerPriv *priv = GET_PRIV (self);
132 g_free (priv->address);
134 G_OBJECT_CLASS (empathy_irc_server_parent_class)->finalize (object);
137 static void
138 empathy_irc_server_init (EmpathyIrcServer *self)
140 EmpathyIrcServerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
141 EMPATHY_TYPE_IRC_SERVER, EmpathyIrcServerPriv);
143 self->priv = priv;
146 static void
147 empathy_irc_server_class_init (EmpathyIrcServerClass *klass)
149 GObjectClass *object_class = G_OBJECT_CLASS (klass);
150 GParamSpec *param_spec;
152 object_class->get_property = empathy_irc_server_get_property;
153 object_class->set_property = empathy_irc_server_set_property;
155 g_type_class_add_private (object_class, sizeof (EmpathyIrcServerPriv));
157 object_class->finalize = empathy_irc_server_finalize;
159 param_spec = g_param_spec_string (
160 "address",
161 "Server address",
162 "The address of this server",
163 NULL,
164 G_PARAM_READWRITE |
165 G_PARAM_STATIC_NAME |
166 G_PARAM_STATIC_NICK |
167 G_PARAM_STATIC_BLURB);
168 g_object_class_install_property (object_class, PROP_ADDRESS, param_spec);
170 param_spec = g_param_spec_uint (
171 "port",
172 "Server port",
173 "The port to use to connect on this server",
174 1, G_MAXUINT16, 6667,
175 G_PARAM_READWRITE |
176 G_PARAM_STATIC_NAME |
177 G_PARAM_STATIC_NICK |
178 G_PARAM_STATIC_BLURB);
179 g_object_class_install_property (object_class, PROP_PORT, param_spec);
181 param_spec = g_param_spec_boolean (
182 "ssl",
183 "SSL",
184 "If this server needs SSL connection",
185 FALSE,
186 G_PARAM_READWRITE |
187 G_PARAM_STATIC_NAME |
188 G_PARAM_STATIC_NICK |
189 G_PARAM_STATIC_BLURB);
190 g_object_class_install_property (object_class, PROP_SSL, param_spec);
193 * EmpathyIrcServer::modified:
194 * @server: the object that received the signal
196 * Emitted when a property of the server is modified.
199 signals[MODIFIED] = g_signal_new (
200 "modified",
201 G_OBJECT_CLASS_TYPE (object_class),
202 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
204 NULL, NULL,
205 g_cclosure_marshal_VOID__VOID,
206 G_TYPE_NONE, 0);
210 * empathy_irc_server_new:
211 * @address: the address
212 * @port: the port
213 * @ssl: %TRUE if the server needs a SSL connection
215 * Creates a new #EmpathyIrcServer
217 * Returns: a new #EmpathyIrcServer
219 EmpathyIrcServer *
220 empathy_irc_server_new (const gchar *address,
221 guint port,
222 gboolean ssl)
224 return g_object_new (EMPATHY_TYPE_IRC_SERVER,
225 "address", address,
226 "port", port,
227 "ssl", ssl,
228 NULL);