[evolution-data-server] Add CamelSmtpSettings.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Add CamelSmtpSettings.
- Date: Mon, 15 Aug 2011 15:56:47 +0000 (UTC)
commit 1ade8f33e49b63563d5466b1cfad4730bc180de3
Author: Matthew Barnes <mbarnes redhat com>
Date: Thu Jul 21 11:29:56 2011 -0500
Add CamelSmtpSettings.
CamelSmtpSettings replaces the various URL parameters used in
CamelSmtpTransport with equivalent GObject properties.
Adapt the smtp provider to use CamelSmtpSettings.
camel/providers/smtp/Makefile.am | 2 +
camel/providers/smtp/camel-smtp-provider.c | 10 +-
camel/providers/smtp/camel-smtp-settings.c | 92 +++++++++++++++++++
camel/providers/smtp/camel-smtp-settings.h | 62 +++++++++++++
camel/providers/smtp/camel-smtp-transport.c | 126 ++-------------------------
5 files changed, 170 insertions(+), 122 deletions(-)
---
diff --git a/camel/providers/smtp/Makefile.am b/camel/providers/smtp/Makefile.am
index e5cc3c8..931f8d3 100644
--- a/camel/providers/smtp/Makefile.am
+++ b/camel/providers/smtp/Makefile.am
@@ -10,6 +10,8 @@ libcamelsmtp_la_CPPFLAGS = \
libcamelsmtp_la_SOURCES = \
camel-smtp-provider.c \
+ camel-smtp-settings.c \
+ camel-smtp-settings.h \
camel-smtp-transport.c
noinst_HEADERS = \
diff --git a/camel/providers/smtp/camel-smtp-provider.c b/camel/providers/smtp/camel-smtp-provider.c
index b4bd7d5..1960e60 100644
--- a/camel/providers/smtp/camel-smtp-provider.c
+++ b/camel/providers/smtp/camel-smtp-provider.c
@@ -39,11 +39,11 @@ static guint smtp_url_hash (gconstpointer key);
static gint smtp_url_equal (gconstpointer a, gconstpointer b);
CamelProviderPortEntry smtp_port_entries[] = {
- { 25, N_("Default SMTP port"), FALSE },
- { 465, N_("SMTP over SSL"), TRUE },
- { 587, N_("Message submission port"), FALSE },
- { 0, NULL, 0 }
- };
+ { 25, N_("Default SMTP port"), FALSE },
+ { 465, N_("SMTP over SSL"), TRUE },
+ { 587, N_("Message submission port"), FALSE },
+ { 0, NULL, 0 }
+};
static CamelProvider smtp_provider = {
"smtp",
diff --git a/camel/providers/smtp/camel-smtp-settings.c b/camel/providers/smtp/camel-smtp-settings.c
new file mode 100644
index 0000000..4a267f3
--- /dev/null
+++ b/camel/providers/smtp/camel-smtp-settings.c
@@ -0,0 +1,92 @@
+/*
+ * camel-smtp-settings.c
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#include "camel-smtp-settings.h"
+
+#define CAMEL_SMTP_SETTINGS_GET_PRIVATE(obj) \
+ (G_TYPE_INSTANCE_GET_PRIVATE \
+ ((obj), CAMEL_TYPE_SMTP_SETTINGS, CamelSmtpSettingsPrivate))
+
+enum {
+ PROP_0,
+ PROP_SECURITY_METHOD
+};
+
+G_DEFINE_TYPE_WITH_CODE (
+ CamelSmtpSettings,
+ camel_smtp_settings,
+ CAMEL_TYPE_SETTINGS,
+ G_IMPLEMENT_INTERFACE (
+ CAMEL_TYPE_NETWORK_SETTINGS, NULL))
+
+static void
+smtp_settings_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_SECURITY_METHOD:
+ camel_network_settings_set_security_method (
+ CAMEL_NETWORK_SETTINGS (object),
+ g_value_get_enum (value));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+smtp_settings_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ switch (property_id) {
+ case PROP_SECURITY_METHOD:
+ g_value_set_enum (
+ value,
+ camel_network_settings_get_security_method (
+ CAMEL_NETWORK_SETTINGS (object)));
+ return;
+ }
+
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+}
+
+static void
+camel_smtp_settings_class_init (CamelSmtpSettingsClass *class)
+{
+ GObjectClass *object_class;
+
+ object_class = G_OBJECT_CLASS (class);
+ object_class->set_property = smtp_settings_set_property;
+ object_class->get_property = smtp_settings_get_property;
+
+ /* Inherited from CamelNetworkSettings. */
+ g_object_class_override_property (
+ object_class,
+ PROP_SECURITY_METHOD,
+ "security-method");
+}
+
+static void
+camel_smtp_settings_init (CamelSmtpSettings *settings)
+{
+}
+
diff --git a/camel/providers/smtp/camel-smtp-settings.h b/camel/providers/smtp/camel-smtp-settings.h
new file mode 100644
index 0000000..59693e7
--- /dev/null
+++ b/camel/providers/smtp/camel-smtp-settings.h
@@ -0,0 +1,62 @@
+/*
+ * camel-smtp-settings.h
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) version 3.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with the program; if not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+#ifndef CAMEL_SMTP_SETTINGS_H
+#define CAMEL_SMTP_SETTINGS_H
+
+#include <camel/camel.h>
+
+/* Standard GObject macros */
+#define CAMEL_TYPE_SMTP_SETTINGS \
+ (camel_smtp_settings_get_type ())
+#define CAMEL_SMTP_SETTINGS(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST \
+ ((obj), CAMEL_TYPE_SMTP_SETTINGS, CamelSmtpSettings))
+#define CAMEL_SMTP_SETTINGS_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_CAST \
+ ((cls), CAMEL_TYPE_SMTP_SETTINGS, CamelSmtpSettingsClass))
+#define CAMEL_IS_SMTP_SETTINGS(obj) \
+ (G_TYPE_CHECK_INSTANCE_TYPE \
+ ((obj), CAMEL_TYPE_SMTP_SETTINGS))
+#define CAMEL_IS_SMTP_SETTINGS_CLASS(cls) \
+ (G_TYPE_CHECK_CLASS_TYPE \
+ ((cls), CAMEL_TYPE_SMTP_SETTINGS))
+#define CAMEL_SMTP_SETTINGS_GET_CLASS(obj) \
+ (G_TYPE_INSTANCE_GET_CLASS \
+ ((obj), CAMEL_TYPE_SMTP_SETTINGS, CamelSmtpSettingsClass))
+
+G_BEGIN_DECLS
+
+typedef struct _CamelSmtpSettings CamelSmtpSettings;
+typedef struct _CamelSmtpSettingsClass CamelSmtpSettingsClass;
+typedef struct _CamelSmtpSettingsPrivate CamelSmtpSettingsPrivate;
+
+struct _CamelSmtpSettings {
+ CamelSettings parent;
+ CamelSmtpSettingsPrivate *priv;
+};
+
+struct _CamelSmtpSettingsClass {
+ CamelSettingsClass parent_class;
+};
+
+GType camel_smtp_settings_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* CAMEL_SMTP_SETTINGS_H */
diff --git a/camel/providers/smtp/camel-smtp-transport.c b/camel/providers/smtp/camel-smtp-transport.c
index 44bffc5..8d071cf 100644
--- a/camel/providers/smtp/camel-smtp-transport.c
+++ b/camel/providers/smtp/camel-smtp-transport.c
@@ -36,6 +36,7 @@
#include <glib/gi18n-lib.h>
+#include "camel-smtp-settings.h"
#include "camel-smtp-transport.h"
#ifdef G_OS_WIN32
@@ -87,13 +88,6 @@ static void smtp_set_error (CamelSmtpTransport *transport,
GCancellable *cancellable,
GError **error);
-enum {
- PROP_0,
- PROP_DEFAULT_PORT,
- PROP_SECURITY_METHOD,
- PROP_SERVICE_NAME
-};
-
/* Forward Declarations */
static void camel_network_service_init (CamelNetworkServiceInterface *interface);
@@ -111,8 +105,8 @@ connect_to_server (CamelService *service,
GError **error)
{
CamelSmtpTransport *transport = CAMEL_SMTP_TRANSPORT (service);
- CamelNetworkService *network_service;
CamelNetworkSecurityMethod method;
+ CamelSettings *settings;
CamelURL *url;
CamelStream *tcp_stream;
gchar *respbuf = NULL;
@@ -126,9 +120,9 @@ connect_to_server (CamelService *service,
transport->authtypes = NULL;
url = camel_service_get_camel_url (service);
+ settings = camel_service_get_settings (service);
- network_service = CAMEL_NETWORK_SERVICE (service);
- method = camel_network_service_get_security_method (network_service);
+ g_object_get (settings, "security-method", &method, NULL);
tcp_stream = camel_network_service_connect_sync (
CAMEL_NETWORK_SERVICE (service), cancellable, error);
@@ -274,81 +268,6 @@ authtypes_free (gpointer key, gpointer value, gpointer data)
g_free (value);
}
-static void
-smtp_transport_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- switch (property_id) {
- case PROP_SECURITY_METHOD:
- camel_network_service_set_security_method (
- CAMEL_NETWORK_SERVICE (object),
- g_value_get_enum (value));
- return;
- }
-
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-}
-
-static void
-smtp_transport_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- switch (property_id) {
- case PROP_DEFAULT_PORT:
- g_value_set_uint (
- value,
- camel_network_service_get_default_port (
- CAMEL_NETWORK_SERVICE (object)));
- return;
-
- case PROP_SECURITY_METHOD:
- g_value_set_enum (
- value,
- camel_network_service_get_security_method (
- CAMEL_NETWORK_SERVICE (object)));
- return;
-
- case PROP_SERVICE_NAME:
- g_value_set_string (
- value,
- camel_network_service_get_service_name (
- CAMEL_NETWORK_SERVICE (object)));
- return;
- }
-
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
-}
-
-static void
-smtp_transport_constructed (GObject *object)
-{
- CamelURL *url;
- const gchar *use_ssl;
-
- /* Chain up to parent's constructed() method. */
- G_OBJECT_CLASS (camel_smtp_transport_parent_class)->constructed (object);
-
- url = camel_service_get_camel_url (CAMEL_SERVICE (object));
- use_ssl = camel_url_get_param (url, "use_ssl");
-
- if (g_strcmp0 (use_ssl, "never") == 0)
- camel_network_service_set_security_method (
- CAMEL_NETWORK_SERVICE (object),
- CAMEL_NETWORK_SECURITY_METHOD_NONE);
- else if (g_strcmp0 (use_ssl, "always") == 0)
- camel_network_service_set_security_method (
- CAMEL_NETWORK_SERVICE (object),
- CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT);
- else if (g_strcmp0 (use_ssl, "when-possible") == 0)
- camel_network_service_set_security_method (
- CAMEL_NETWORK_SERVICE (object),
- CAMEL_NETWORK_SECURITY_METHOD_STARTTLS_ON_STANDARD_PORT);
-}
-
static gchar *
smtp_transport_get_name (CamelService *service, gboolean brief)
{
@@ -710,13 +629,11 @@ smtp_transport_send_to_sync (CamelTransport *transport,
}
static const gchar *
-smtp_transport_get_service_name (CamelNetworkService *service)
+smtp_transport_get_service_name (CamelNetworkService *service,
+ CamelNetworkSecurityMethod method)
{
- CamelNetworkSecurityMethod method;
const gchar *service_name;
- method = camel_network_service_get_security_method (service);
-
switch (method) {
case CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT:
service_name = "smtps";
@@ -731,13 +648,11 @@ smtp_transport_get_service_name (CamelNetworkService *service)
}
static guint16
-smtp_transport_get_default_port (CamelNetworkService *service)
+smtp_transport_get_default_port (CamelNetworkService *service,
+ CamelNetworkSecurityMethod method)
{
- CamelNetworkSecurityMethod method;
guint16 default_port;
- method = camel_network_service_get_security_method (service);
-
switch (method) {
case CAMEL_NETWORK_SECURITY_METHOD_SSL_ON_ALTERNATE_PORT:
default_port = SMTPS_PORT;
@@ -754,16 +669,11 @@ smtp_transport_get_default_port (CamelNetworkService *service)
static void
camel_smtp_transport_class_init (CamelSmtpTransportClass *class)
{
- GObjectClass *object_class;
CamelServiceClass *service_class;
CamelTransportClass *transport_class;
- object_class = G_OBJECT_CLASS (class);
- object_class->set_property = smtp_transport_set_property;
- object_class->get_property = smtp_transport_get_property;
- object_class->constructed = smtp_transport_constructed;
-
service_class = CAMEL_SERVICE_CLASS (class);
+ service_class->settings_type = CAMEL_TYPE_SMTP_SETTINGS;
service_class->get_name = smtp_transport_get_name;
service_class->connect_sync = smtp_transport_connect_sync;
service_class->disconnect_sync = smtp_transport_disconnect_sync;
@@ -771,24 +681,6 @@ camel_smtp_transport_class_init (CamelSmtpTransportClass *class)
transport_class = CAMEL_TRANSPORT_CLASS (class);
transport_class->send_to_sync = smtp_transport_send_to_sync;
-
- /* Inherited from CamelNetworkService. */
- g_object_class_override_property (
- object_class,
- PROP_DEFAULT_PORT,
- "default-port");
-
- /* Inherited from CamelNetworkService. */
- g_object_class_override_property (
- object_class,
- PROP_SECURITY_METHOD,
- "security-method");
-
- /* Inherited from CamelNetworkService. */
- g_object_class_override_property (
- object_class,
- PROP_SERVICE_NAME,
- "service-name");
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]