]> git.0d.be Git - empathy.git/blob - libempathy/empathy-irc-server.c
Updated Basque language
[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 <string.h>
23 #include <stdlib.h>
24 #include <glib.h>
25 #include <glib/gi18n-lib.h>
26
27 #include <telepathy-glib/util.h>
28
29 #include "empathy-marshal.h"
30 #include "empathy-irc-server.h"
31 #include "empathy-utils.h"
32
33 #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyIrcServer)
34 typedef struct
35 {
36   gchar *address;
37   gint port;
38   gboolean ssl;
39 } EmpathyIrcServerPriv;
40
41 /* properties */
42 enum
43 {
44   PROP_ADDRESS = 1,
45   PROP_PORT,
46   PROP_SSL,
47   LAST_PROPERTY
48 };
49
50 /* signals */
51 enum
52 {
53   MODIFIED,
54   LAST_SIGNAL
55 };
56
57 static guint signals[LAST_SIGNAL] = {0};
58
59 G_DEFINE_TYPE (EmpathyIrcServer, empathy_irc_server, G_TYPE_OBJECT);
60
61 static void
62 empathy_irc_server_get_property (GObject *object,
63                                  guint property_id,
64                                  GValue *value,
65                                  GParamSpec *pspec)
66 {
67   EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
68   EmpathyIrcServerPriv *priv = GET_PRIV (self);
69
70   switch (property_id)
71     {
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;
84     }
85 }
86
87 static void
88 empathy_irc_server_set_property (GObject *object,
89                                  guint property_id,
90                                  const GValue *value,
91                                  GParamSpec *pspec)
92 {
93   EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
94   EmpathyIrcServerPriv *priv = GET_PRIV (self);
95
96   switch (property_id)
97     {
98       case PROP_ADDRESS:
99         if (tp_strdiff (priv->address, g_value_get_string (value)))
100           {
101             g_free (priv->address);
102             priv->address = g_value_dup_string (value);
103             g_signal_emit (object, signals[MODIFIED], 0);
104           }
105         break;
106       case PROP_PORT:
107         if (priv->port != g_value_get_uint (value))
108           {
109             priv->port = g_value_get_uint (value);
110             g_signal_emit (object, signals[MODIFIED], 0);
111           }
112         break;
113       case PROP_SSL:
114         if (priv->ssl != g_value_get_boolean (value))
115           {
116             priv->ssl = g_value_get_boolean (value);
117             g_signal_emit (object, signals[MODIFIED], 0);
118           }
119         break;
120       default:
121         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
122         break;
123     }
124 }
125
126 static void
127 empathy_irc_server_finalize (GObject *object)
128 {
129   EmpathyIrcServer *self = EMPATHY_IRC_SERVER (object);
130   EmpathyIrcServerPriv *priv = GET_PRIV (self);
131
132   g_free (priv->address);
133
134   G_OBJECT_CLASS (empathy_irc_server_parent_class)->finalize (object);
135 }
136
137 static void
138 empathy_irc_server_init (EmpathyIrcServer *self)
139 {
140   EmpathyIrcServerPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
141       EMPATHY_TYPE_IRC_SERVER, EmpathyIrcServerPriv);
142
143   self->priv = priv;
144 }
145
146 static void
147 empathy_irc_server_class_init (EmpathyIrcServerClass *klass)
148 {
149   GObjectClass *object_class = G_OBJECT_CLASS (klass);
150   GParamSpec *param_spec;
151
152   object_class->get_property = empathy_irc_server_get_property;
153   object_class->set_property = empathy_irc_server_set_property;
154
155   g_type_class_add_private (object_class, sizeof (EmpathyIrcServerPriv));
156
157   object_class->finalize = empathy_irc_server_finalize;
158
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);
169
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);
180
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);
191
192   /**
193    * EmpathyIrcServer::modified:
194    * @server: the object that received the signal
195    *
196    * Emitted when a property of the server is modified.
197    *
198    */
199   signals[MODIFIED] = g_signal_new (
200       "modified",
201       G_OBJECT_CLASS_TYPE (object_class),
202       G_SIGNAL_RUN_LAST | G_SIGNAL_DETAILED,
203       0,
204       NULL, NULL,
205       g_cclosure_marshal_VOID__VOID,
206       G_TYPE_NONE, 0);
207 }
208
209 /**
210  * empathy_irc_server_new:
211  * @address: the address
212  * @port: the port
213  * @ssl: %TRUE if the server needs a SSL connection
214  *
215  * Creates a new #EmpathyIrcServer
216  *
217  * Returns: a new #EmpathyIrcServer
218  */
219 EmpathyIrcServer *
220 empathy_irc_server_new (const gchar *address,
221                         guint port,
222                         gboolean ssl)
223 {
224   return g_object_new (EMPATHY_TYPE_IRC_SERVER,
225       "address", address,
226       "port", port,
227       "ssl", ssl,
228       NULL);
229 }