]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Added dispose and finalize to Solipa object.
authorAndrea Zagli <azagli@libero.it>
Sun, 3 Apr 2011 07:23:22 +0000 (09:23 +0200)
committerAndrea Zagli <azagli@libero.it>
Sun, 3 Apr 2011 07:23:22 +0000 (09:23 +0200)
src/solipa.c
tests/allegato.c

index e6476a25cb37ccf9d6034c1a098a504eeacb4f0e..1d1ce5ddb941189665650097ac128bce55f3cb07 100644 (file)
@@ -40,11 +40,15 @@ static void solipa_get_property (GObject *object,
                                GValue *value,
                                GParamSpec *pspec);
 
+static void solipa_dispose (GObject *gobject);
+static void solipa_finalize (GObject *gobject);
+
 #define SOLIPA_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), SOLIPA_TYPE, SolipaPrivate))
 
 typedef struct _SolipaPrivate SolipaPrivate;
 struct _SolipaPrivate
        {
+               gchar *camel_tmpdir;
                CamelSession *camel_session;
 
                GdaEx *gdaex;
@@ -63,6 +67,8 @@ solipa_class_init (SolipaClass *class)
 
        object_class->set_property = solipa_set_property;
        object_class->get_property = solipa_get_property;
+       object_class->dispose = solipa_dispose;
+       object_class->finalize = solipa_finalize;
 
        g_type_class_add_private (object_class, sizeof (SolipaPrivate));
 }
@@ -84,8 +90,6 @@ Solipa
        Solipa *solipa;
        SolipaPrivate *priv;
 
-       gchar *camel_tmpdir;
-
        /* inizializzo GType e GThread */
        g_type_init ();
        g_thread_init (NULL);
@@ -94,13 +98,13 @@ Solipa
        priv = SOLIPA_GET_PRIVATE (solipa);
 
        /* creo la directory temporanea per camel */
-       camel_tmpdir = g_mkdtemp (g_build_filename (g_get_tmp_dir (), g_strdup ("solipa-camel-XXXXXX"), NULL));
+       priv->camel_tmpdir = g_mkdtemp (g_build_filename (g_get_tmp_dir (), g_strdup ("solipa-camel-XXXXXX"), NULL));
 
        /* inizializzo camel */
-       camel_init (camel_tmpdir, FALSE);
+       camel_init (priv->camel_tmpdir, FALSE);
        camel_provider_init ();
 
-       priv->camel_session = solipa_camel_session_new (camel_tmpdir);
+       priv->camel_session = solipa_camel_session_new (priv->camel_tmpdir);
 
        /* gui */
 #ifdef G_OS_WIN32
@@ -268,7 +272,6 @@ solipa_set_property (GObject *object,
                    GParamSpec *pspec)
 {
        Solipa *solipa = (Solipa *)object;
-
        SolipaPrivate *priv = SOLIPA_GET_PRIVATE (solipa);
 
        switch (property_id)
@@ -286,7 +289,6 @@ solipa_get_property (GObject *object,
                    GParamSpec *pspec)
 {
        Solipa *solipa = (Solipa *)object;
-
        SolipaPrivate *priv = SOLIPA_GET_PRIVATE (solipa);
 
        switch (property_id)
@@ -296,3 +298,48 @@ solipa_get_property (GObject *object,
                                break;
                }
 }
+
+static void
+solipa_dispose (GObject *gobject)
+{
+       Solipa *solipa = (Solipa *)gobject;
+       SolipaPrivate *priv = SOLIPA_GET_PRIVATE (solipa);
+
+       if (priv->gdaex)
+               {
+                       g_object_unref (priv->gdaex);
+                       priv->gdaex = NULL;
+               }
+
+       if (priv->gtkbuilder)
+               {
+                       g_object_unref (priv->gtkbuilder);
+                       priv->gtkbuilder = NULL;
+               }
+
+       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_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);
+
+       GObjectClass *parent_class = g_type_class_peek_parent (G_OBJECT_GET_CLASS (gobject));
+       parent_class->finalize (gobject);
+}
index 0aa255b709ca1a79a70f096eeebab3b0cc8b4726..269f97bb7b98c8880f9bcc8c2fd867db95d5e4b6 100644 (file)
@@ -71,5 +71,7 @@ main (int argc, char *argv[])
 
        gtk_main ();
 
+       g_object_unref (solipa);
+
        return 0;
 }