1 /*
2  * e-mail-config-welcome-page.c
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; if not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17 
18 #include "evolution-config.h"
19 
20 #include <glib/gi18n-lib.h>
21 
22 #include <e-util/e-util.h>
23 #include <libebackend/libebackend.h>
24 
25 #include "e-mail-config-welcome-page.h"
26 
27 #define E_MAIL_CONFIG_WELCOME_PAGE_GET_PRIVATE(obj) \
28 	(G_TYPE_INSTANCE_GET_PRIVATE \
29 	((obj), E_TYPE_MAIL_CONFIG_WELCOME_PAGE, EMailConfigWelcomePagePrivate))
30 
31 struct _EMailConfigWelcomePagePrivate {
32 	gchar *text;
33 	GtkBox *main_box; /* not referenced */
34 };
35 
36 enum {
37 	PROP_0,
38 	PROP_TEXT
39 };
40 
41 /* Forward Declarations */
42 static void	e_mail_config_welcome_page_interface_init
43 					(EMailConfigPageInterface *iface);
44 
G_DEFINE_TYPE_WITH_CODE(EMailConfigWelcomePage,e_mail_config_welcome_page,GTK_TYPE_SCROLLED_WINDOW,G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE,NULL)G_IMPLEMENT_INTERFACE (E_TYPE_MAIL_CONFIG_PAGE,e_mail_config_welcome_page_interface_init))45 G_DEFINE_TYPE_WITH_CODE (
46 	EMailConfigWelcomePage,
47 	e_mail_config_welcome_page,
48 	GTK_TYPE_SCROLLED_WINDOW,
49 	G_IMPLEMENT_INTERFACE (
50 		E_TYPE_EXTENSIBLE, NULL)
51 	G_IMPLEMENT_INTERFACE (
52 		E_TYPE_MAIL_CONFIG_PAGE,
53 		e_mail_config_welcome_page_interface_init))
54 
55 static void
56 mail_config_welcome_page_set_property (GObject *object,
57                                        guint property_id,
58                                        const GValue *value,
59                                        GParamSpec *pspec)
60 {
61 	switch (property_id) {
62 		case PROP_TEXT:
63 			e_mail_config_welcome_page_set_text (
64 				E_MAIL_CONFIG_WELCOME_PAGE (object),
65 				g_value_get_string (value));
66 			return;
67 	}
68 
69 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
70 }
71 
72 static void
mail_config_welcome_page_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)73 mail_config_welcome_page_get_property (GObject *object,
74                                        guint property_id,
75                                        GValue *value,
76                                        GParamSpec *pspec)
77 {
78 	switch (property_id) {
79 		case PROP_TEXT:
80 			g_value_set_string (
81 				value,
82 				e_mail_config_welcome_page_get_text (
83 				E_MAIL_CONFIG_WELCOME_PAGE (object)));
84 			return;
85 	}
86 
87 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
88 }
89 
90 static void
mail_config_welcome_page_finalize(GObject * object)91 mail_config_welcome_page_finalize (GObject *object)
92 {
93 	EMailConfigWelcomePagePrivate *priv;
94 
95 	priv = E_MAIL_CONFIG_WELCOME_PAGE_GET_PRIVATE (object);
96 
97 	g_free (priv->text);
98 
99 	/* Chain up to parent's finalize() method. */
100 	G_OBJECT_CLASS (e_mail_config_welcome_page_parent_class)->
101 		finalize (object);
102 }
103 
104 static void
mail_config_welcome_page_constructed(GObject * object)105 mail_config_welcome_page_constructed (GObject *object)
106 {
107 	EMailConfigWelcomePage *page;
108 	GtkWidget *widget;
109 	GtkWidget *main_box;
110 
111 	page = E_MAIL_CONFIG_WELCOME_PAGE (object);
112 
113 	/* Chain up to parent's constructed() method. */
114 	G_OBJECT_CLASS (e_mail_config_welcome_page_parent_class)->constructed (object);
115 
116 	main_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
117 	gtk_widget_set_valign (GTK_WIDGET (main_box), GTK_ALIGN_FILL);
118 	gtk_widget_set_vexpand (GTK_WIDGET (main_box), TRUE);
119 
120 	page->priv->main_box = GTK_BOX (main_box);
121 
122 	widget = gtk_label_new (NULL);
123 	gtk_widget_set_valign (widget, GTK_ALIGN_FILL);
124 	gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE);
125 	gtk_label_set_width_chars (GTK_LABEL (widget), 20);
126 	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
127 	gtk_box_pack_start (GTK_BOX (main_box), widget, TRUE, TRUE, 0);
128 	gtk_widget_show (widget);
129 
130 	e_binding_bind_object_text_property (
131 		page, "text",
132 		widget, "label",
133 		G_BINDING_BIDIRECTIONAL |
134 		G_BINDING_SYNC_CREATE);
135 
136 	e_mail_config_page_set_content (E_MAIL_CONFIG_PAGE (page), main_box);
137 
138 	e_extensible_load_extensions (E_EXTENSIBLE (page));
139 }
140 
141 static void
e_mail_config_welcome_page_class_init(EMailConfigWelcomePageClass * class)142 e_mail_config_welcome_page_class_init (EMailConfigWelcomePageClass *class)
143 {
144 	GObjectClass *object_class;
145 
146 	g_type_class_add_private (
147 		class, sizeof (EMailConfigWelcomePagePrivate));
148 
149 	object_class = G_OBJECT_CLASS (class);
150 	object_class->set_property = mail_config_welcome_page_set_property;
151 	object_class->get_property = mail_config_welcome_page_get_property;
152 	object_class->finalize = mail_config_welcome_page_finalize;
153 	object_class->constructed = mail_config_welcome_page_constructed;
154 
155 	g_object_class_install_property (
156 		object_class,
157 		PROP_TEXT,
158 		g_param_spec_string (
159 			"text",
160 			"Text",
161 			"Welcome message",
162 			_("Welcome to the Evolution Mail Configuration "
163 			"Assistant.\n\nClick “Next” to begin."),
164 			G_PARAM_READWRITE |
165 			G_PARAM_CONSTRUCT |
166 			G_PARAM_STATIC_STRINGS));
167 }
168 
169 static void
e_mail_config_welcome_page_interface_init(EMailConfigPageInterface * iface)170 e_mail_config_welcome_page_interface_init (EMailConfigPageInterface *iface)
171 {
172 	iface->title = _("Welcome");
173 	iface->page_type = GTK_ASSISTANT_PAGE_INTRO;
174 	iface->sort_order = E_MAIL_CONFIG_WELCOME_PAGE_SORT_ORDER;
175 }
176 
177 static void
e_mail_config_welcome_page_init(EMailConfigWelcomePage * page)178 e_mail_config_welcome_page_init (EMailConfigWelcomePage *page)
179 {
180 	page->priv = E_MAIL_CONFIG_WELCOME_PAGE_GET_PRIVATE (page);
181 }
182 
183 EMailConfigPage *
e_mail_config_welcome_page_new(void)184 e_mail_config_welcome_page_new (void)
185 {
186 	return g_object_new (E_TYPE_MAIL_CONFIG_WELCOME_PAGE, NULL);
187 }
188 
189 const gchar *
e_mail_config_welcome_page_get_text(EMailConfigWelcomePage * page)190 e_mail_config_welcome_page_get_text (EMailConfigWelcomePage *page)
191 {
192 	g_return_val_if_fail (E_IS_MAIL_CONFIG_WELCOME_PAGE (page), NULL);
193 
194 	return page->priv->text;
195 }
196 
197 void
e_mail_config_welcome_page_set_text(EMailConfigWelcomePage * page,const gchar * text)198 e_mail_config_welcome_page_set_text (EMailConfigWelcomePage *page,
199                                      const gchar *text)
200 {
201 	g_return_if_fail (E_IS_MAIL_CONFIG_WELCOME_PAGE (page));
202 
203 	if (g_strcmp0 (page->priv->text, (text != NULL) ? text : "") == 0)
204 		return;
205 
206 	g_free (page->priv->text);
207 	page->priv->text = g_strdup ((text != NULL) ? text : "");
208 
209 	g_object_notify (G_OBJECT (page), "text");
210 }
211 
212 GtkBox *
e_mail_config_welcome_page_get_main_box(EMailConfigWelcomePage * page)213 e_mail_config_welcome_page_get_main_box (EMailConfigWelcomePage *page)
214 {
215 	g_return_val_if_fail (E_IS_MAIL_CONFIG_WELCOME_PAGE (page), NULL);
216 
217 	return page->priv->main_box;
218 }
219