account-settings: use TpProtocol's API to get TpConnectionManagerParam
[empathy-mirror.git] / libempathy / empathy-irc-server.c
blobcb1fbfc2fe13daa36339edb2da3b520e8c708712
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-irc-server.h"
30 #include "empathy-utils.h"
32 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIrcServer)
33 typedef struct
35 gchar *address;
36 guint port;
37 gboolean ssl;
38 } EmpathyIrcServerPriv;
40 /* properties */
41 enum
43 PROP_ADDRESS = 1,
44 PROP_PORT,
45 PROP_SSL,
46 LAST_PROPERTY
49 /* signals */
50 enum
52 MODIFIED,
53 LAST_SIGNAL
56 static guint signals[LAST_SIGNAL] = {0};
58 G_DEFINE_TYPE (EmpathyIrcServer, empathy_irc_server, G_TYPE_OBJECT);
60 static void
61 empathy_irc_server_get_property (GObject *object,
62 guint property_id,
63 GValue *value,
64 GParamSpec *pspec)
66 EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
67 EmpathyIrcServerPriv *priv = GET_PRIV (self);
69 switch (property_id)
71 case PROP_ADDRESS:
72 g_value_set_string (value, priv->address);
73 break;
74 case PROP_PORT:
75 g_value_set_uint (value, priv->port);
76 break;
77 case PROP_SSL:
78 g_value_set_boolean (value, priv->ssl);
79 break;
80 default:
81 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
82 break;
86 static void
87 empathy_irc_server_set_property (GObject *object,
88 guint property_id,
89 const GValue *value,
90 GParamSpec *pspec)
92 EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
93 EmpathyIrcServerPriv *priv = GET_PRIV (self);
95 switch (property_id)
97 case PROP_ADDRESS:
98 if (tp_strdiff (priv->address, g_value_get_string (value)))
100 g_free (priv->address);
101 priv->address = g_value_dup_string (value);
102 g_signal_emit (object, signals[MODIFIED], 0);
104 break;
105 case PROP_PORT:
106 if (priv->port != g_value_get_uint (value))
108 priv->port = g_value_get_uint (value);
109 g_signal_emit (object, signals[MODIFIED], 0);
111 break;
112 case PROP_SSL:
113 if (priv->ssl != g_value_get_boolean (value))
115 priv->ssl = g_value_get_boolean (value);
116 g_signal_emit (object, signals[MODIFIED], 0);
118 break;
119 default:
120 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
121 break;
125 static void
126 empathy_irc_server_finalize (GObject *object)
128 EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
129 EmpathyIrcServerPriv *priv = GET_PRIV (self);
131 g_free (priv->address);
133 G_OBJECT_CLASS (empathy_irc_server_parent_class)->finalize (object);
136 static void
137 empathy_irc_server_init (EmpathyIrcServer *self)
139 EmpathyIrcServerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
140 EMPATHY_TYPE_IRC_SERVER, EmpathyIrcServerPriv);
142 self->priv = priv;
145 static void
146 empathy_irc_server_class_init (EmpathyIrcServerClass *klass)
148 GObjectClass *object_class = G_OBJECT_CLASS (klass);
149 GParamSpec *param_spec;
151 object_class->get_property = empathy_irc_server_get_property;
152 object_class->set_property = empathy_irc_server_set_property;
154 g_type_class_add_private (object_class, sizeof (EmpathyIrcServerPriv));
156 object_class->finalize = empathy_irc_server_finalize;
158 param_spec = g_param_spec_string (
159 "address",
160 "Server address",
161 "The address of this server",
162 NULL,
163 G_PARAM_READWRITE |
164 G_PARAM_STATIC_NAME |
165 G_PARAM_STATIC_NICK |
166 G_PARAM_STATIC_BLURB);
167 g_object_class_install_property (object_class, PROP_ADDRESS, param_spec);
169 param_spec = g_param_spec_uint (
170 "port",
171 "Server port",
172 "The port to use to connect on this server",
173 1, G_MAXUINT16, 6667,
174 G_PARAM_READWRITE |
175 G_PARAM_STATIC_NAME |
176 G_PARAM_STATIC_NICK |
177 G_PARAM_STATIC_BLURB);
178 g_object_class_install_property (object_class, PROP_PORT, param_spec);
180 param_spec = g_param_spec_boolean (
181 "ssl",
182 "SSL",
183 "If this server needs SSL connection",
184 FALSE,
185 G_PARAM_READWRITE |
186 G_PARAM_STATIC_NAME |
187 G_PARAM_STATIC_NICK |
188 G_PARAM_STATIC_BLURB);
189 g_object_class_install_property (object_class, PROP_SSL, param_spec);
192 * EmpathyIrcServer::modified:
193 * @server: the object that received the signal
195 * Emitted when a property of the server is modified.
198 signals[MODIFIED] = g_signal_new (
199 "modified",
200 G_OBJECT_CLASS_TYPE (object_class),
201 G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
203 NULL, NULL,
204 g_cclosure_marshal_generic,
205 G_TYPE_NONE, 0);
209 * empathy_irc_server_new:
210 * @address: the address
211 * @port: the port
212 * @ssl: %TRUE if the server needs a SSL connection
214 * Creates a new #EmpathyIrcServer
216 * Returns: a new #EmpathyIrcServer
218 EmpathyIrcServer *
219 empathy_irc_server_new (const gchar *address,
220 guint port,
221 gboolean ssl)
223 return g_object_new (EMPATHY_TYPE_IRC_SERVER,
224 "address", address,
225 "port", port,
226 "ssl", ssl,
227 NULL);