1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /* camelService.c : Abstract class for an email service */
7 * Bertrand Guiheneuf <bertrand@helixcode.com>
9 * Copyright 1999, 2000 HelixCode (http://www.helixcode.com) .
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of the
14 * License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 #include "camel-service.h"
28 #include "camel-log.h"
30 static GtkObjectClass *parent_class=NULL;
32 /* Returns the class for a CamelService */
33 #define CSERV_CLASS(so) CAMEL_SERVICE_CLASS (GTK_OBJECT(so)->klass)
35 static gboolean _connect(CamelService *service, CamelException *ex);
36 static gboolean _connect_with_url (CamelService *service, Gurl *url,
38 static gboolean _disconnect(CamelService *service, CamelException *ex);
39 static gboolean _is_connected (CamelService *service);
40 static void _finalize (GtkObject *object);
43 camel_service_class_init (CamelServiceClass *camel_service_class)
45 GtkObjectClass *gtk_object_class =
46 GTK_OBJECT_CLASS (camel_service_class);
48 parent_class = gtk_type_class (gtk_object_get_type ());
50 /* virtual method definition */
51 camel_service_class->connect = _connect;
52 camel_service_class->connect_with_url = _connect_with_url;
53 camel_service_class->disconnect = _disconnect;
54 camel_service_class->is_connected = _is_connected;
56 /* virtual method overload */
57 gtk_object_class->finalize = _finalize;
61 camel_service_get_type (void)
63 static GtkType camel_service_type = 0;
65 if (!camel_service_type) {
66 GtkTypeInfo camel_service_info =
69 sizeof (CamelService),
70 sizeof (CamelServiceClass),
71 (GtkClassInitFunc) camel_service_class_init,
72 (GtkObjectInitFunc) NULL,
73 /* reserved_1 */ NULL,
74 /* reserved_2 */ NULL,
75 (GtkClassInitFunc) NULL,
78 camel_service_type = gtk_type_unique (gtk_object_get_type (),
82 return camel_service_type;
87 _finalize (GtkObject *object)
89 CamelService *camel_service = CAMEL_SERVICE (object);
91 CAMEL_LOG_FULL_DEBUG ("Entering CamelService::finalize\n");
93 if (camel_service->url)
94 g_url_free (camel_service->url);
96 GTK_OBJECT_CLASS (parent_class)->finalize (object);
97 CAMEL_LOG_FULL_DEBUG ("Leaving CamelService::finalize\n");
103 * _connect : connect to a service
105 * connect to the service using the parameters
106 * stored in the session it is initialized with
107 * WARNING: session not implemented for the moment
109 * @service: object to connect
112 _connect (CamelService *service, CamelException *ex)
114 #warning need to get default URL from somewhere
115 return CSERV_CLASS(service)->connect_with_url(service, NULL, ex);
121 * camel_service_connect:connect to a service
122 * @service: CamelService object
124 * connect to the service using the parameters
125 * stored in the session it is initialized with
126 * WARNING: session not implemented for the moment
130 camel_service_connect (CamelService *service, CamelException *ex)
132 return CSERV_CLASS(service)->connect(service, ex);
138 * _connect_with_url: connect to the specified address
140 * Connect to the service, but do not use the session
141 * default parameters to retrieve server's address
143 * @service: object to connect
144 * @url: URL describing service to connect to
147 _connect_with_url (CamelService *service, Gurl *url, CamelException *ex)
149 service->connected = TRUE;
156 * camel_service_connect_with_url: connect a service
157 * @service: the service to connect
158 * @url: URL describing the service to connect to
160 * Connect to a service, but do not use the session
161 * default parameters to retrieve server's address
165 camel_service_connect_with_url (CamelService *service, char *url,
168 return CSERV_CLASS(service)->connect_with_url (service, g_url_new(url),
175 * _disconnect : disconnect from a service
177 * disconnect from the service
179 * @service: object to disconnect
182 _disconnect (CamelService *service, CamelException *ex)
184 service->connected = FALSE;
186 g_url_free(service->url);
196 * camel_service_disconnect: disconnect from a service
197 * @service: CamelService object
200 camel_service_disconnect (CamelService *service, CamelException *ex)
202 return CSERV_CLASS(service)->disconnect(service, ex);
208 * _is_connected: test if the service object is connected
209 * @service: object to test
214 _is_connected (CamelService *service)
216 return service->connected;
221 * camel_service_is_connected: test if the service object is connected
222 * @service: object to test
227 camel_service_is_connected (CamelService *service)
229 return CSERV_CLASS(service)->is_connected(service);
234 * camel_service_get_url: get the url representing a service
235 * @service: the service
237 * returns the URL representing a service. For security reasons
238 * This routine does not return the password.
240 * Return value: the url name
243 camel_service_get_url (CamelService *service)
245 return g_url_to_string(service->url, FALSE);