1 /* Copyright (c) 2006, Nokia Corporation
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * * Neither the name of the Nokia Corporation nor the names of its
14 * contributors may be used to endorse or promote products derived from
15 * this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
18 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
20 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
21 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
24 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
25 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include "modest-signature-editor-dialog.h"
31 #include "widgets/modest-ui-constants.h"
32 #include "modest-hildon-includes.h"
33 #include "widgets/modest-serversecurity-combo-box.h"
34 #include "widgets/modest-secureauth-combo-box.h"
35 #include "widgets/modest-validating-entry.h"
36 #include "modest-runtime.h"
37 #include <modest-account-mgr-helpers.h>
38 #include <gtk/gtkcheckbutton.h>
39 #include <gtk/gtkhbox.h>
40 #include <gtk/gtkvbox.h>
41 #include <gtk/gtktextview.h>
42 #include <gtk/gtklabel.h>
43 #include <gtk/gtkscrolledwindow.h>
44 #include <gtk/gtkstock.h>
45 #include <glib/gi18n.h>
46 #include <modest-maemo-utils.h>
48 G_DEFINE_TYPE (ModestSignatureEditorDialog, modest_signature_editor_dialog, GTK_TYPE_DIALOG);
50 #define SIGNATURE_EDITOR_DIALOG_GET_PRIVATE(o) \
51 (G_TYPE_INSTANCE_GET_PRIVATE ((o), MODEST_TYPE_SIGNATURE_EDITOR_DIALOG, ModestSignatureEditorDialogPrivate))
53 typedef struct _ModestSignatureEditorDialogPrivate ModestSignatureEditorDialogPrivate;
55 struct _ModestSignatureEditorDialogPrivate
57 GtkWidget *checkbox_use;
59 GtkWidget *scrolledwindow;
64 modest_signature_editor_dialog_get_property (GObject *object, guint property_id,
65 GValue *value, GParamSpec *pspec)
67 switch (property_id) {
69 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
74 modest_signature_editor_dialog_set_property (GObject *object, guint property_id,
75 const GValue *value, GParamSpec *pspec)
77 switch (property_id) {
79 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
84 modest_signature_editor_dialog_dispose (GObject *object)
86 if (G_OBJECT_CLASS (modest_signature_editor_dialog_parent_class)->dispose)
87 G_OBJECT_CLASS (modest_signature_editor_dialog_parent_class)->dispose (object);
91 modest_signature_editor_dialog_finalize (GObject *object)
93 G_OBJECT_CLASS (modest_signature_editor_dialog_parent_class)->finalize (object);
97 modest_signature_editor_dialog_class_init (ModestSignatureEditorDialogClass *klass)
99 GObjectClass *object_class = G_OBJECT_CLASS (klass);
101 g_type_class_add_private (klass, sizeof (ModestSignatureEditorDialogPrivate));
103 object_class->get_property = modest_signature_editor_dialog_get_property;
104 object_class->set_property = modest_signature_editor_dialog_set_property;
105 object_class->dispose = modest_signature_editor_dialog_dispose;
106 object_class->finalize = modest_signature_editor_dialog_finalize;
110 enable_widgets (ModestSignatureEditorDialog *self)
112 ModestSignatureEditorDialogPrivate *priv =
113 SIGNATURE_EDITOR_DIALOG_GET_PRIVATE (self);
115 const gboolean enable = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_use));
116 gtk_widget_set_sensitive (priv->label, enable);
117 gtk_widget_set_sensitive (priv->scrolledwindow, enable);
118 gtk_text_view_set_editable (GTK_TEXT_VIEW (priv->textview), enable);
122 on_toggle_button_changed (GtkToggleButton *togglebutton, gpointer user_data)
124 ModestSignatureEditorDialog *self = MODEST_SIGNATURE_EDITOR_DIALOG (user_data);
125 enable_widgets (self);
129 modest_signature_editor_dialog_init (ModestSignatureEditorDialog *self)
131 ModestSignatureEditorDialogPrivate *priv =
132 SIGNATURE_EDITOR_DIALOG_GET_PRIVATE (self);
134 gtk_window_set_title (GTK_WINDOW (self), _("mcen_ti_email_signatures_edit_title"));
136 GtkWidget *box = GTK_DIALOG(self)->vbox; /* gtk_vbox_new (FALSE, MODEST_MARGIN_HALF); */
137 gtk_container_set_border_width (GTK_CONTAINER (box), MODEST_MARGIN_HALF);
139 priv->checkbox_use = gtk_check_button_new_with_label (
140 _("mcen_fi_email_signatures_use_signature"));
141 gtk_box_pack_start (GTK_BOX (box), priv->checkbox_use, FALSE, FALSE, MODEST_MARGIN_HALF);
142 gtk_widget_show (priv->checkbox_use);
144 g_signal_connect (G_OBJECT (priv->checkbox_use), "toggled",
145 G_CALLBACK (on_toggle_button_changed), self);
148 priv->label = gtk_label_new (""); /* Set in modest_signature_editor_dialog_set_settings(). */
149 gtk_box_pack_start (GTK_BOX (box), priv->label, FALSE, FALSE, MODEST_MARGIN_HALF);
150 gtk_widget_show (priv->label);
152 priv->scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
153 gtk_container_set_border_width (GTK_CONTAINER (priv->scrolledwindow), MODEST_MARGIN_DEFAULT);
154 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (priv->scrolledwindow),
155 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
156 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (priv->scrolledwindow), GTK_SHADOW_IN);
157 gtk_box_pack_start (GTK_BOX (box), priv->scrolledwindow, FALSE, FALSE, MODEST_MARGIN_HALF);
158 gtk_widget_show (priv->scrolledwindow);
160 priv->textview = gtk_text_view_new ();
161 gtk_container_add (GTK_CONTAINER (priv->scrolledwindow), priv->textview);
162 gtk_widget_show (priv->textview);
163 GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->textview));
164 gtk_text_buffer_set_text (buffer, "--\n", -1); /* Default, as per the UI spec. */
166 /* Add the buttons: */
167 gtk_dialog_add_button (GTK_DIALOG (self), _("mcen_bd_dialog_ok"), GTK_RESPONSE_OK);
168 gtk_dialog_add_button (GTK_DIALOG (self), _("mcen_bd_dialog_cancel"), GTK_RESPONSE_CANCEL);
170 gtk_widget_show (box);
171 gtk_widget_set_size_request (GTK_WIDGET (self), 480, -1);
173 /* When this window is shown, hibernation should not be possible,
174 * because there is no sensible way to save the state: */
175 modest_window_mgr_prevent_hibernation_while_window_is_shown (
176 modest_runtime_get_window_mgr (), GTK_WINDOW (self));
178 hildon_help_dialog_help_enable (GTK_DIALOG(self), "applications_email_signatureeditor",
179 modest_maemo_utils_get_osso_context());
182 ModestSignatureEditorDialog*
183 modest_signature_editor_dialog_new (void)
185 return g_object_new (MODEST_TYPE_SIGNATURE_EDITOR_DIALOG, NULL);
189 modest_signature_editor_dialog_set_settings (
190 ModestSignatureEditorDialog *window, gboolean use_signature, const gchar* signature,
191 const gchar* account_title)
193 ModestSignatureEditorDialogPrivate *priv =
194 SIGNATURE_EDITOR_DIALOG_GET_PRIVATE (window);
196 /* This causes a warning because of the %s in the translation, but not in the original string: */
197 gchar* label_text = g_strdup_printf (_("mcen_ia_email_signatures_edit_dlg_label"),
199 gtk_label_set_text (GTK_LABEL (priv->label), label_text);
200 gtk_label_set_ellipsize (GTK_LABEL (priv->label), PANGO_ELLIPSIZE_NONE);
203 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (priv->checkbox_use), use_signature);
205 GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->textview));
207 gtk_text_buffer_set_text (buffer, signature, -1);
209 gtk_text_buffer_set_text (buffer, "--\n", -1); /* Default, as per the UI spec. */
211 enable_widgets (window);
215 * The result must be freed with g_free(). */
217 modest_signature_editor_dialog_get_settings (
218 ModestSignatureEditorDialog *window, gboolean* use_signature)
220 ModestSignatureEditorDialogPrivate *priv =
221 SIGNATURE_EDITOR_DIALOG_GET_PRIVATE (window);
223 g_assert(use_signature);
225 *use_signature = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->checkbox_use));
227 GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->textview));
229 GtkTextIter start, end;
230 gtk_text_buffer_get_bounds (buffer, &start, &end);
231 return gtk_text_buffer_get_text (buffer, &start, &end, TRUE);