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)
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)
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,
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);
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);
if (!ret)
{
/* send email */
+ solipa_mail_ui_send (solipa_mail_ui);
}
}
\ No newline at end of file
#include <mailui.h>
+Solipa *solipa;
+SolipaMailUI *mailui;
+
GtkWidget *w;
GtkWidget *mailui_w;
on_btn_ok_clicked (gpointer instance, gpointer user_data)
{
g_debug ("OK clicked");
+ solipa_mail_ui_send (mailui);
}
gboolean
GError *error;
GtkBuilder *builder;
- Solipa *solipa;
- SolipaMailUI *mailui;
-
gtk_init (&argc, &argv);
solipa = solipa_new ();
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 ();