]> git.0d.be Git - empathy.git/blob - libempathy/empathy-irc-server.c
Reorder header inclusions accordingly to the Telepathy coding style
[empathy.git] / libempathy / empathy-irc-server.c
1 /*
2  * Copyright (C) 2007-2008 Guillaume Desmottes
3  *
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.
8  *
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.
13  *
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
17  *
18  * Authors: Guillaume Desmottes <gdesmott@gnome.org>
19  */
20
21 #include "config.h"
22 #include "empathy-irc-server.h"
23
24 #include "empathy-utils.h"
25
26 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIrcServer)
27 typedef struct
28 {
29   gchar *address;
30   guint port;
31   gboolean ssl;
32 } EmpathyIrcServerPriv;
33
34 /* properties */
35 enum
36 {
37   PROP_ADDRESS = 1,
38   PROP_PORT,
39   PROP_SSL,
40   LAST_PROPERTY
41 };
42
43 /* signals */
44 enum
45 {
46   MODIFIED,
47   LAST_SIGNAL
48 };
49
50 static guint signals[LAST_SIGNAL] = {0};
51
52 G_DEFINE_TYPE (EmpathyIrcServer, empathy_irc_server, G_TYPE_OBJECT);
53
54 static void
55 empathy_irc_server_get_property (GObject *object,
56                                  guint property_id,
57                                  GValue *value,
58                                  GParamSpec *pspec)
59 {
60   EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
61   EmpathyIrcServerPriv *priv = GET_PRIV (self);
62
63   switch (property_id)
64     {
65       case PROP_ADDRESS:
66         g_value_set_string (value, priv->address);
67         break;
68       case PROP_PORT:
69         g_value_set_uint (value, priv->port);
70         break;
71       case PROP_SSL:
72         g_value_set_boolean (value, priv->ssl);
73         break;
74       default:
75         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
76         break;
77     }
78 }
79
80 static void
81 empathy_irc_server_set_property (GObject *object,
82                                  guint property_id,
83                                  const GValue *value,
84                                  GParamSpec *pspec)
85 {
86   EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
87   EmpathyIrcServerPriv *priv = GET_PRIV (self);
88
89   switch (property_id)
90     {
91       case PROP_ADDRESS:
92         if (tp_strdiff (priv->address, g_value_get_string (value)))
93           {
94             g_free (priv->address);
95             priv->address = g_value_dup_string (value);
96             g_signal_emit (object, signals[MODIFIED], 0);
97           }
98         break;
99       case PROP_PORT:
100         if (priv->port != g_value_get_uint (value))
101           {
102             priv->port = g_value_get_uint (value);
103             g_signal_emit (object, signals[MODIFIED], 0);
104           }
105         break;
106       case PROP_SSL:
107         if (priv->ssl != g_value_get_boolean (value))
108           {
109             priv->ssl = g_value_get_boolean (value);
110             g_signal_emit (object, signals[MODIFIED], 0);
111           }
112         break;
113       default:
114         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
115         break;
116     }
117 }
118
119 static void
120 empathy_irc_server_finalize (GObject *object)
121 {
122   EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
123   EmpathyIrcServerPriv *priv = GET_PRIV (self);
124
125   g_free (priv->address);
126
127   G_OBJECT_CLASS (empathy_irc_server_parent_class)->finalize (object);
128 }
129
130 static void
131 empathy_irc_server_init (EmpathyIrcServer *self)
132 {
133   EmpathyIrcServerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
134       EMPATHY_TYPE_IRC_SERVER, EmpathyIrcServerPriv);
135
136   self->priv = priv;
137 }
138
139 static void
140 empathy_irc_server_class_init (EmpathyIrcServerClass *klass)
141 {
142   GObjectClass *object_class = G_OBJECT_CLASS (klass);
143   GParamSpec *param_spec;
144
145   object_class->get_property = empathy_irc_server_get_property;
146   object_class->set_property = empathy_irc_server_set_property;
147
148   g_type_class_add_private (object_class, sizeof (EmpathyIrcServerPriv));
149
150   object_class->finalize = empathy_irc_server_finalize;
151
152   param_spec = g_param_spec_string (
153       "address",
154       "Server address",
155       "The address of this server",
156       NULL,
157       G_PARAM_READWRITE |
158       G_PARAM_STATIC_NAME |
159       G_PARAM_STATIC_NICK |
160       G_PARAM_STATIC_BLURB);
161   g_object_class_install_property (object_class, PROP_ADDRESS, param_spec);
162
163   param_spec = g_param_spec_uint (
164       "port",
165       "Server port",
166       "The port to use to connect on this server",
167       1, G_MAXUINT16, 6667,
168       G_PARAM_READWRITE |
169       G_PARAM_STATIC_NAME |
170       G_PARAM_STATIC_NICK |
171       G_PARAM_STATIC_BLURB);
172   g_object_class_install_property (object_class, PROP_PORT, param_spec);
173
174   param_spec = g_param_spec_boolean (
175       "ssl",
176       "SSL",
177       "If this server needs SSL connection",
178       FALSE,
179       G_PARAM_READWRITE |
180       G_PARAM_STATIC_NAME |
181       G_PARAM_STATIC_NICK |
182       G_PARAM_STATIC_BLURB);
183   g_object_class_install_property (object_class, PROP_SSL, param_spec);
184
185   /**
186    * EmpathyIrcServer::modified:
187    * @server: the object that received the signal
188    *
189    * Emitted when a property of the server is modified.
190    *
191    */
192   signals[MODIFIED] = g_signal_new (
193       "modified",
194       G_OBJECT_CLASS_TYPE (object_class),
195       G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
196       0,
197       NULL, NULL,
198       g_cclosure_marshal_generic,
199       G_TYPE_NONE, 0);
200 }
201
202 /**
203  * empathy_irc_server_new:
204  * @address: the address
205  * @port: the port
206  * @ssl: %TRUE if the server needs a SSL connection
207  *
208  * Creates a new #EmpathyIrcServer
209  *
210  * Returns: a new #EmpathyIrcServer
211  */
212 EmpathyIrcServer *
213 empathy_irc_server_new (const gchar *address,
214                         guint port,
215                         gboolean ssl)
216 {
217   return g_object_new (EMPATHY_TYPE_IRC_SERVER,
218       "address", address,
219       "port", port,
220       "ssl", ssl,
221       NULL);
222 }