From 8005c75b5bb58a3765e89da57009048a21481773 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sat, 8 Apr 2017 10:24:48 +0200 Subject: [PATCH] =?utf8?q?Inizio=20scorporamento=20utilit=C3=A0=20per=20ma?= =?utf8?q?il=20da=20libreria=20principale.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- configure.ac | 1 + libsolipa.pc.in | 2 +- libsolipamail.pc.in | 11 +++ src/Makefile.am | 39 ++++++---- src/camel.c | 186 ++++++++++++++++++++++++++++++++++++++++++++ src/camel.h | 62 +++++++++++++++ src/solipa.c | 28 ++----- src/solipa.h | 10 ++- tests/Makefile.am | 11 +++ 9 files changed, 309 insertions(+), 41 deletions(-) create mode 100644 libsolipamail.pc.in create mode 100644 src/camel.c create mode 100644 src/camel.h diff --git a/configure.ac b/configure.ac index 4d18dad..bc294e4 100644 --- a/configure.ac +++ b/configure.ac @@ -119,6 +119,7 @@ AC_SUBST(SOLIPA_WIN32_LIBS) # Output files AC_CONFIG_FILES([ libsolipa.pc + libsolipamail.pc libsolipaooo.pc Makefile src/Makefile diff --git a/libsolipa.pc.in b/libsolipa.pc.in index 8cd2dce..1bedbd9 100644 --- a/libsolipa.pc.in +++ b/libsolipa.pc.in @@ -6,6 +6,6 @@ includedir=@includedir@ Name: @PACKAGE_NAME@ Description: Classe con funzioni varie di utilità. Version: @PACKAGE_VERSION@ -Requires: libgdaex >= 0.5.0 @CAMEL_PKGCONFIG@ libgtkform >= 0.5.0 gio-2.0 >= 2.36 libzakutils libzakformgtk +Requires: libgdaex >= 0.5.0 libgtkform >= 0.5.0 gio-2.0 >= 2.36 libzakutils libzakformgtk Libs: -L${libdir} -lsolipa Cflags: -I${includedir} diff --git a/libsolipamail.pc.in b/libsolipamail.pc.in new file mode 100644 index 0000000..030a7a4 --- /dev/null +++ b/libsolipamail.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: @PACKAGE_NAME@ +Description: Classe con funzioni varie di utilità - Supporto per le mail. +Version: @PACKAGE_VERSION@ +Requires: libsolipa @CAMEL_PKGCONFIG@ +Libs: -L${libdir} -lsolipamail +Cflags: -I${includedir} diff --git a/src/Makefile.am b/src/Makefile.am index db5a209..b411d19 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -8,8 +8,8 @@ endif LIBS = $(SOLIPA_LIBS) \ $(SOLIPA_WIN32_LIBS) \ - $(CAMEL_LIBS) \ - $(WIN32_LIBS) + $(WIN32_LIBS) \ + $(CAMEL_LIBS) if HAVE_CAMEL318 CAMEL3=-DCAMEL3=\"yes\" -DCAMEL318=\"yes\" @@ -27,34 +27,49 @@ endif AM_CPPFLAGS = $(SOLIPA_CFLAGS) \ $(SOLIPA_WIN32_CFLAGS) \ - $(CAMEL_CFLAGS) \ -DGUIDIR=\""$(guidir)"\" \ -DG_LOG_DOMAIN=\"Solipa\" \ + $(CAMEL_CFLAGS) \ $(CAMEL3) lib_LTLIBRARIES = libsolipa.la \ + libsolipamail.la \ libsolipaooo.la libsolipa_la_SOURCES = solipa.c \ allegato.c \ - camelsession.c \ log.c \ - mail.c \ - mailui.c \ progresswindow.c \ - utils.c + utils.c \ + camelsession.c \ + camel.c libsolipa_la_LDFLAGS = -no-undefined libsolipa_include_HEADERS = libsolipa.h \ solipa.h \ allegato.h \ - camelsession.h \ log.h \ - mail.h \ - mailui.h \ progresswindow.h \ - utils.h + utils.h \ + camelsession.h \ + camel.h + +libsolipa_includedir = $(includedir)/libsolipa + +libsolipamail_la_LIBADD = libsolipa.la + +libsolipamail_la_CFLAGS = + +libsolipamail_la_LDFLAGS = -no-undefined + +libsolipamail_la_SOURCES = mail.c \ + mailui.c + +libsolipamail_include_HEADERS = mail.h \ + mailui.h + +libsolipamail_includedir = $(includedir)/libsolipa libsolipaooo_la_LIBADD = libsolipa.la \ $(PYTHON_LIBS) @@ -67,6 +82,4 @@ libsolipaooo_la_SOURCES = ooo.c libsolipaooo_include_HEADERS = ooo.h -libsolipa_includedir = $(includedir)/libsolipa - libsolipaooo_includedir = $(includedir)/libsolipa diff --git a/src/camel.c b/src/camel.c new file mode 100644 index 0000000..bf01cb3 --- /dev/null +++ b/src/camel.c @@ -0,0 +1,186 @@ +/* + * Copyright (C) 2017 Andrea Zagli + * + * This library 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.1 of the License, or (at your option) any later version. + * + * This library 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 this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifdef HAVE_CONFIG_H + #include +#endif + +#ifdef G_OS_WIN32 +#include +#endif + +#include + +#include "solipa.h" +#include "camelsession.h" +#include "camel.h" + +static void solipa_camel_class_init (SolipaCamelClass *class); +static void solipa_camel_init (SolipaCamel *solipa); + +static void solipa_camel_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void solipa_camel_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void solipa_camel_dispose (GObject *gobject); +static void solipa_camel_finalize (GObject *gobject); + +#define SOLIPA_CAMEL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SOLIPA_TYPE_CAMEL, SolipaCamelPrivate)) + +typedef struct _SolipaCamelPrivate SolipaCamelPrivate; +struct _SolipaCamelPrivate + { + gchar *camel_tmpdir; + CamelSession *camel_session; + }; + +G_DEFINE_TYPE (SolipaCamel, solipa_camel, G_TYPE_OBJECT) + +static void +solipa_camel_class_init (SolipaCamelClass *class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (class); + + object_class->set_property = solipa_camel_set_property; + object_class->get_property = solipa_camel_get_property; + object_class->dispose = solipa_camel_dispose; + object_class->finalize = solipa_camel_finalize; + + g_type_class_add_private (object_class, sizeof (SolipaCamelPrivate)); +} + +static void +solipa_camel_init (SolipaCamel *solipa) +{ + SolipaCamelPrivate *priv = SOLIPA_CAMEL_GET_PRIVATE (solipa); +} + +/** + * solipa_camel_new: + * + * Returns: the newly created #SolipaCamel object. + */ +SolipaCamel +*solipa_camel_new () +{ + SolipaCamel *solipa; + SolipaCamelPrivate *priv; + + solipa = SOLIPA_CAMEL (g_object_new (solipa_camel_get_type (), NULL)); + priv = SOLIPA_CAMEL_GET_PRIVATE (solipa); + + /* creo la directory temporanea per camel */ + priv->camel_tmpdir = g_mkdtemp (g_build_filename (g_get_tmp_dir (), g_strdup ("solipa-camel-XXXXXX"), NULL)); + + /* inizializzo camel */ + camel_init (priv->camel_tmpdir, FALSE); + camel_provider_init (); + + priv->camel_session = solipa_camel_session_new (priv->camel_tmpdir); + + return solipa; +} + +CamelSession +*solipa_camel_get_camel_session (SolipaCamel *solipa) +{ + SolipaCamelPrivate *priv; + + g_return_val_if_fail (IS_SOLIPA (solipa), NULL); + + priv = SOLIPA_CAMEL_GET_PRIVATE (solipa); + + return priv->camel_session; +} + +/* PRIVATE */ +static void +solipa_camel_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + SolipaCamel *solipa = (SolipaCamel *)object; + SolipaCamelPrivate *priv = SOLIPA_CAMEL_GET_PRIVATE (solipa); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +solipa_camel_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + SolipaCamel *solipa = (SolipaCamel *)object; + SolipaCamelPrivate *priv = SOLIPA_CAMEL_GET_PRIVATE (solipa); + + switch (property_id) + { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +solipa_camel_dispose (GObject *gobject) +{ + SolipaCamel *solipa = (SolipaCamel *)gobject; + SolipaCamelPrivate *priv = SOLIPA_CAMEL_GET_PRIVATE (solipa); + + if (priv->camel_tmpdir) + { + /* rimuovo la directory temporanea */ + g_rmdir (priv->camel_tmpdir); + } + + if (priv->camel_session) + { + g_object_unref (priv->camel_session); + priv->camel_session = NULL; + } + + GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); + parent_class->dispose (gobject); +} + +static void +solipa_camel_finalize (GObject *gobject) +{ + SolipaCamel *solipa = (SolipaCamel *)gobject; + SolipaCamelPrivate *priv = SOLIPA_CAMEL_GET_PRIVATE (solipa); + + /* delete camel tmp dir */ + g_rmdir (priv->camel_tmpdir); + + g_free (priv->camel_tmpdir); + + GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject)); + parent_class->finalize (gobject); +} diff --git a/src/camel.h b/src/camel.h new file mode 100644 index 0000000..1fd36fb --- /dev/null +++ b/src/camel.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2017 Andrea Zagli + * + * This library 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.1 of the License, or (at your option) any later version. + * + * This library 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 this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef __SOLIPA_CAMEL_H__ +#define __SOLIPA_CAMEL_H__ + +#include +#include + +#include + + +G_BEGIN_DECLS + + +#define SOLIPA_TYPE_CAMEL (solipa_camel_get_type ()) +#define SOLIPA_CAMEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SOLIPA_TYPE_CAMEL, SolipaCamel)) +#define SOLIPA_CAMEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SOLIPA_TYPE_CAMEL, SolipaCamelClass)) +#define IS_SOLIPA_CAMEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SOLIPA_TYPE_CAMEL)) +#define IS_SOLIPA_CAMEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SOLIPA_TYPE_CAMEL)) +#define SOLIPA_CAMEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SOLIPA_TYPE_CAMEL, SolipaCamelClass)) + +typedef struct _SolipaCamel SolipaCamel; +typedef struct _SolipaCamelClass SolipaCamelClass; + +struct _SolipaCamel + { + GObject parent; + }; + +struct _SolipaCamelClass + { + GObjectClass parent_class; + }; + +GType solipa_camel_get_type (void) G_GNUC_CONST; + + +SolipaCamel *solipa_camel_new (void); + +CamelSession *solipa_camel_get_camel_session (SolipaCamel *solipa_camel); + + +G_END_DECLS + + +#endif /* __SOLIPA_CAMEL_H__ */ diff --git a/src/solipa.c b/src/solipa.c index b3c1f25..293a5f5 100644 --- a/src/solipa.c +++ b/src/solipa.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 Andrea Zagli + * Copyright (C) 2010-2017 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -30,7 +30,6 @@ #endif #include "solipa.h" -#include "camelsession.h" #include "utils.h" static void solipa_class_init (SolipaClass *class); @@ -53,8 +52,7 @@ static void solipa_finalize (GObject *gobject); typedef struct _SolipaPrivate SolipaPrivate; struct _SolipaPrivate { - gchar *camel_tmpdir; - CamelSession *camel_session; + SolipaCamel *camel_session; gchar *guidir; gchar *guifile; @@ -115,14 +113,7 @@ Solipa solipa = SOLIPA (g_object_new (solipa_get_type (), NULL)); priv = SOLIPA_GET_PRIVATE (solipa); - /* creo la directory temporanea per camel */ - priv->camel_tmpdir = g_mkdtemp (g_build_filename (g_get_tmp_dir (), g_strdup ("solipa-camel-XXXXXX"), NULL)); - - /* inizializzo camel */ - camel_init (priv->camel_tmpdir, FALSE); - camel_provider_init (); - - priv->camel_session = solipa_camel_session_new (priv->camel_tmpdir); + priv->camel_session = solipa_camel_new (); /* gui */ #ifdef G_OS_WIN32 @@ -201,7 +192,8 @@ solipa_set_from_keyfile (Solipa *solipa, const gchar *filename) g_error_free (error); } -CamelSession +G_DEPRECATED +SolipaCamel *solipa_get_camel_session (Solipa *solipa) { SolipaPrivate *priv; @@ -297,12 +289,6 @@ solipa_dispose (GObject *gobject) priv->gtkbuilder = NULL; } - if (priv->camel_tmpdir) - { - /* rimuovo la directory temporanea */ - g_rmdir (priv->camel_tmpdir); - } - if (priv->camel_session) { g_object_unref (priv->camel_session); @@ -319,10 +305,6 @@ solipa_finalize (GObject *gobject) Solipa *solipa = (Solipa *)gobject; SolipaPrivate *priv = SOLIPA_GET_PRIVATE (solipa); - /* delete camel tmp dir */ - g_rmdir (priv->camel_tmpdir); - - g_free (priv->camel_tmpdir); g_free (priv->guidir); g_free (priv->guifile); diff --git a/src/solipa.h b/src/solipa.h index 13122f0..acb81f3 100644 --- a/src/solipa.h +++ b/src/solipa.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 Andrea Zagli + * Copyright (C) 2010-2017 Andrea Zagli * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -24,11 +24,12 @@ #include -#include - #include +#include "camel.h" + + G_BEGIN_DECLS @@ -60,7 +61,8 @@ Solipa *solipa_new_with_keyfile (const gchar *filename); void solipa_set_from_keyfile (Solipa *solipa, const gchar *filename); -CamelSession *solipa_get_camel_session (Solipa *solipa); +G_DEPRECATED +SolipaCamel *solipa_get_camel_session (Solipa *solipa); G_DEPRECATED void solipa_set_gdaex (Solipa *solipa, GdaEx *gdaex); diff --git a/tests/Makefile.am b/tests/Makefile.am index 6c4bf75..a39695f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,15 +2,26 @@ AM_CPPFLAGS = $(WARN_CFLAGS) \ $(DISABLE_DEPRECATED_CFLAGS) \ $(SOLIPA_CFLAGS) \ $(CAMEL_CFLAGS) \ + $(PYTHON_CFLAGS) \ -I$(top_srcdir)/src \ -DGUIDIR="\"@abs_builddir@\"" LIBS = $(SOLIPA_LIBS) \ $(CAMEL_LIBS) \ + $(PYTHON_LIBS) \ -export-dynamic LDADD = $(top_builddir)/src/libsolipa.la +mail_LDADD = $(top_builddir)/src/libsolipa.la \ + $(top_builddir)/src/libsolipamail.la +mail_check_address_LDADD = $(top_builddir)/src/libsolipa.la \ + $(top_builddir)/src/libsolipamail.la +mail_get_addresses_from_string_LDADD = $(top_builddir)/src/libsolipa.la \ + $(top_builddir)/src/libsolipamail.la +mailui_LDADD = $(top_builddir)/src/libsolipa.la \ + $(top_builddir)/src/libsolipamail.la + ooo_LDADD = $(top_builddir)/src/libsolipaooo.la ooo_pycmd_LDADD = $(top_builddir)/src/libsolipaooo.la -- 2.49.0