]> saetta.ns0.it Git - solipa/libsolipa/commitdiff
Aggiunta la funzione SolipaMailUI::send.
authorAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 5 May 2011 15:30:33 +0000 (17:30 +0200)
committerAndrea Zagli <a.zagli@comune.scandicci.fi.it>
Thu, 5 May 2011 15:30:33 +0000 (17:30 +0200)
src/mailui.c
src/mailui.h
tests/mailui.c

index 526b5757d51c680b811ba0cfbcb92e46f6b1d41d..2390c15121de814bef0a464d493a46a2453f5981 100644 (file)
@@ -243,6 +243,8 @@ SolipaMailUI
 GtkWidget
 *solipa_mail_ui_get_dialog (SolipaMailUI *mailui)
 {
+       g_return_val_if_fail (IS_SOLIPA_MAIL_UI (mailui), NULL);
+
        SolipaMailUIPrivate *priv = SOLIPA_MAIL_UI_GET_PRIVATE (mailui);
 
        if (gtk_widget_get_parent (priv->widget) == NULL)
@@ -262,6 +264,8 @@ GtkWidget
 GtkWidget
 *solipa_mail_ui_get_widget (SolipaMailUI *mailui)
 {
+       g_return_val_if_fail (IS_SOLIPA_MAIL_UI (mailui), NULL);
+
        SolipaMailUIPrivate *priv = SOLIPA_MAIL_UI_GET_PRIVATE (mailui);
 
        if (gtk_widget_get_parent (priv->widget) != NULL)
@@ -273,6 +277,103 @@ GtkWidget
        return priv->widget;
 }
 
+gboolean
+solipa_mail_ui_send (SolipaMailUI *mailui)
+{
+       gboolean ret;
+
+       gchar *smtpuri;
+       gchar *from;
+       gchar *to;
+       gchar *cc;
+       gchar *bcc;
+       gchar *subject;
+       gchar *body;
+
+       CamelInternetAddress *addr;
+
+       g_return_val_if_fail (IS_SOLIPA_MAIL_UI (mailui), FALSE);
+
+       SolipaMailUIPrivate *priv = SOLIPA_MAIL_UI_GET_PRIVATE (mailui);
+
+       SolipaMail *smail = solipa_mail_new (priv->solipa);
+       if (smail == NULL)
+               {
+                       g_warning ("Impossibile creare l'oggetto SolipaMail.");
+                       return FALSE;
+               }
+
+       g_object_get (G_OBJECT (mailui),
+                     "smtp-uri", &smtpuri,
+                     "from", &from,
+                     "to", &to,
+                     "cc", &cc,
+                     "bcc", &bcc,
+                     "subject", &subject,
+                     "body", &body,
+                     NULL);
+
+       solipa_mail_set_subject (smail, subject);
+
+       if (g_strcmp0 (g_strstrip (from), "") != 0)
+               {
+                       addr = camel_internet_address_new ();
+                       camel_internet_address_add (addr, "Prova from", from);
+                       solipa_mail_set_from (smail, addr);
+                       camel_address_remove (CAMEL_ADDRESS (addr), -1);
+               }
+       else
+               {
+                       g_warning ("Campo Da: mancante.");
+                       return FALSE;
+               }
+
+       if (g_strcmp0 (g_strstrip (to), "") != 0)
+               {
+                       camel_internet_address_add (addr, "Prova to", to);
+                       solipa_mail_add_recipient (smail, addr, SOLIPA_MAIL_RECIPIENT_TYPE_TO);
+                       camel_address_remove (CAMEL_ADDRESS (addr), -1);
+               }
+       else
+               {
+                       g_warning ("Campo A: mancante.");
+                       return FALSE;
+               }
+
+       if (g_strcmp0 (g_strstrip (cc), "") != 0)
+               {
+                       camel_internet_address_add (addr, "Prova cc", cc);
+                       solipa_mail_add_recipient (smail, addr, SOLIPA_MAIL_RECIPIENT_TYPE_CC);
+                       camel_address_remove (CAMEL_ADDRESS (addr), -1);
+               }
+
+       if (g_strcmp0 (g_strstrip (bcc), "") != 0)
+               {
+                       camel_internet_address_add (addr, "Prova bcc", bcc);
+                       solipa_mail_add_recipient (smail, addr, SOLIPA_MAIL_RECIPIENT_TYPE_BCC);
+                       camel_address_remove (CAMEL_ADDRESS (addr), -1);
+               }
+
+       g_object_unref (addr);
+
+       solipa_mail_set_body (smail, body, NULL);
+
+       if (g_strcmp0 (g_strstrip (smtpuri), "") != 0)
+               {
+                       solipa_mail_send (smail, smtpuri);
+               }
+       else
+               {
+                       g_warning ("URI smtp mancante.");
+                       return FALSE;
+               }
+
+       g_object_unref (smail);
+
+       ret = TRUE;
+       return ret;
+}
+
 /* PRIVATE */
 static void
 solipa_mail_ui_set_property (GObject *object,
@@ -310,8 +411,14 @@ solipa_mail_ui_set_property (GObject *object,
                                break;
 
                        case PROP_BODY:
-                               gtk_entry_set_text (GTK_ENTRY (priv->body), g_strstrip (g_value_dup_string (value)));
-                               break;
+                               {
+                                       GtkTextBuffer *buffer;
+
+                                       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->body));
+
+                                       gtk_text_buffer_set_text (buffer, g_strstrip (g_value_dup_string (value)), -1);
+                                       break;
+                               }
 
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -355,8 +462,17 @@ solipa_mail_ui_get_property (GObject *object,
                                break;
 
                        case PROP_BODY:
-                               g_value_set_string (value, gtk_entry_get_text (GTK_ENTRY (priv->body)));
-                               break;
+                               {
+                                       GtkTextBuffer *buffer;
+                                       GtkTextIter start;
+                                       GtkTextIter end;
+
+                                       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->body));
+                                       gtk_text_buffer_get_bounds (buffer, &start, &end);
+
+                                       g_value_set_string (value, gtk_text_buffer_get_text (buffer, &start, &end, FALSE));
+                                       break;
+                               }
 
                        default:
                                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -402,5 +518,6 @@ solipa_mail_ui_on_ok_clicked (GtkButton *button,
        if (!ret)
                {
                        /* send email */
+                       solipa_mail_ui_send (solipa_mail_ui);
                }
 }
\ No newline at end of file
index e906cbc63da54511b0fd735924b51f136bfa0c74..61aa0a5d24f5cef642c4b58ef8e47f37e5344226 100644 (file)
@@ -59,6 +59,8 @@ SolipaMailUI *solipa_mail_ui_new (Solipa *solipa);
 GtkWidget *solipa_mail_ui_get_dialog (SolipaMailUI *mailui);
 GtkWidget *solipa_mail_ui_get_widget (SolipaMailUI *mailui);
 
+gboolean solipa_mail_ui_send (SolipaMailUI *mailui);
+
 
 G_END_DECLS
 
index ad036426029b946aef658dabc136a04caf783163..7161cd3d083f9bf609923b3d09fac0934d35a204 100644 (file)
@@ -18,6 +18,9 @@
 
 #include <mailui.h>
 
+Solipa *solipa;
+SolipaMailUI *mailui;
+
 GtkWidget *w;
 GtkWidget *mailui_w;
 
@@ -32,6 +35,7 @@ static void
 on_btn_ok_clicked (gpointer instance, gpointer user_data)
 {
        g_debug ("OK clicked");
+       solipa_mail_ui_send (mailui);
 }
 
 gboolean
@@ -48,9 +52,6 @@ main (int argc, char *argv[])
        GError *error;
        GtkBuilder *builder;
 
-       Solipa *solipa;
-       SolipaMailUI *mailui;
-
        gtk_init (&argc, &argv);
 
        solipa = solipa_new ();
@@ -95,6 +96,15 @@ main (int argc, char *argv[])
        g_signal_connect (gtk_builder_get_object (builder, "button2"), "clicked",
                          G_CALLBACK (on_btn_ok_clicked), NULL);
 
+       g_object_set (G_OBJECT (mailui),
+                     "smtp-uri", "smtp://mail.comune.scandicci.fi.it/",
+                     "from", "a.zagli@comune.scandicci.fi.it",
+                     "to", "a.zagli@comune.scandicci.fi.it",
+                     "subject", "Da SolipaMailUI",
+                     "body", "Il body della mail\n"
+                             " con a capo\t\te tab\n\nprova prova",
+                     NULL);
+
        gtk_widget_show (w);
 
        gtk_main ();