1 /*
2  * e-shell-sidebar.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  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
18  *
19  */
20 
21 /**
22  * SECTION: e-shell-sidebar
23  * @short_description: the left side of the main window
24  * @include: shell/e-shell-sidebar.h
25  **/
26 
27 #include "evolution-config.h"
28 
29 #include "e-shell-sidebar.h"
30 
31 #include <libebackend/libebackend.h>
32 
33 #include <shell/e-shell-view.h>
34 
35 #define E_SHELL_SIDEBAR_GET_PRIVATE(obj) \
36 	(G_TYPE_INSTANCE_GET_PRIVATE \
37 	((obj), E_TYPE_SHELL_SIDEBAR, EShellSidebarPrivate))
38 
39 struct _EShellSidebarPrivate {
40 
41 	gpointer shell_view;  /* weak pointer */
42 
43 	GtkWidget *event_box;
44 	GtkWidget *image_widget;
45 
46 	gchar *icon_name;
47 	gchar *primary_text;
48 	gchar *secondary_text;
49 };
50 
51 enum {
52 	PROP_0,
53 	PROP_ICON_NAME,
54 	PROP_PRIMARY_TEXT,
55 	PROP_SECONDARY_TEXT,
56 	PROP_SHELL_VIEW
57 };
58 
59 /* Forward Declarations */
60 static void	e_shell_sidebar_alert_sink_init
61 					(EAlertSinkInterface *iface);
62 
G_DEFINE_TYPE_WITH_CODE(EShellSidebar,e_shell_sidebar,GTK_TYPE_BIN,G_IMPLEMENT_INTERFACE (E_TYPE_ALERT_SINK,e_shell_sidebar_alert_sink_init)G_IMPLEMENT_INTERFACE (E_TYPE_EXTENSIBLE,NULL))63 G_DEFINE_TYPE_WITH_CODE (
64 	EShellSidebar,
65 	e_shell_sidebar,
66 	GTK_TYPE_BIN,
67 	G_IMPLEMENT_INTERFACE (
68 		E_TYPE_ALERT_SINK, e_shell_sidebar_alert_sink_init)
69 	G_IMPLEMENT_INTERFACE (
70 		E_TYPE_EXTENSIBLE, NULL))
71 
72 static void
73 shell_sidebar_set_shell_view (EShellSidebar *shell_sidebar,
74                               EShellView *shell_view)
75 {
76 	g_return_if_fail (shell_sidebar->priv->shell_view == NULL);
77 
78 	shell_sidebar->priv->shell_view = shell_view;
79 
80 	g_object_add_weak_pointer (
81 		G_OBJECT (shell_view),
82 		&shell_sidebar->priv->shell_view);
83 }
84 
85 static void
shell_sidebar_set_property(GObject * object,guint property_id,const GValue * value,GParamSpec * pspec)86 shell_sidebar_set_property (GObject *object,
87                             guint property_id,
88                             const GValue *value,
89                             GParamSpec *pspec)
90 {
91 	switch (property_id) {
92 		case PROP_ICON_NAME:
93 			e_shell_sidebar_set_icon_name (
94 				E_SHELL_SIDEBAR (object),
95 				g_value_get_string (value));
96 			return;
97 
98 		case PROP_PRIMARY_TEXT:
99 			e_shell_sidebar_set_primary_text (
100 				E_SHELL_SIDEBAR (object),
101 				g_value_get_string (value));
102 			return;
103 
104 		case PROP_SECONDARY_TEXT:
105 			e_shell_sidebar_set_secondary_text (
106 				E_SHELL_SIDEBAR (object),
107 				g_value_get_string (value));
108 			return;
109 
110 		case PROP_SHELL_VIEW:
111 			shell_sidebar_set_shell_view (
112 				E_SHELL_SIDEBAR (object),
113 				g_value_get_object (value));
114 			return;
115 	}
116 
117 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
118 }
119 
120 static void
shell_sidebar_get_property(GObject * object,guint property_id,GValue * value,GParamSpec * pspec)121 shell_sidebar_get_property (GObject *object,
122                             guint property_id,
123                             GValue *value,
124                             GParamSpec *pspec)
125 {
126 	switch (property_id) {
127 		case PROP_ICON_NAME:
128 			g_value_set_string (
129 				value, e_shell_sidebar_get_icon_name (
130 				E_SHELL_SIDEBAR (object)));
131 			return;
132 
133 		case PROP_PRIMARY_TEXT:
134 			g_value_set_string (
135 				value, e_shell_sidebar_get_primary_text (
136 				E_SHELL_SIDEBAR (object)));
137 			return;
138 
139 		case PROP_SECONDARY_TEXT:
140 			g_value_set_string (
141 				value, e_shell_sidebar_get_secondary_text (
142 				E_SHELL_SIDEBAR (object)));
143 			return;
144 
145 		case PROP_SHELL_VIEW:
146 			g_value_set_object (
147 				value, e_shell_sidebar_get_shell_view (
148 				E_SHELL_SIDEBAR (object)));
149 			return;
150 	}
151 
152 	G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
153 }
154 
155 static void
shell_sidebar_dispose(GObject * object)156 shell_sidebar_dispose (GObject *object)
157 {
158 	EShellSidebarPrivate *priv;
159 
160 	priv = E_SHELL_SIDEBAR_GET_PRIVATE (object);
161 
162 	if (priv->shell_view != NULL) {
163 		g_object_remove_weak_pointer (
164 			G_OBJECT (priv->shell_view), &priv->shell_view);
165 		priv->shell_view = NULL;
166 	}
167 
168 	/* Unparent the widget before destroying it to avoid
169 	 * writing a custom GtkContainer::remove() method. */
170 
171 	if (priv->event_box != NULL) {
172 		gtk_widget_unparent (priv->event_box);
173 		gtk_widget_destroy (priv->event_box);
174 	}
175 
176 	g_clear_object (&priv->event_box);
177 
178 	/* Chain up to parent's dispose() method. */
179 	G_OBJECT_CLASS (e_shell_sidebar_parent_class)->dispose (object);
180 }
181 
182 static void
shell_sidebar_finalize(GObject * object)183 shell_sidebar_finalize (GObject *object)
184 {
185 	EShellSidebarPrivate *priv;
186 
187 	priv = E_SHELL_SIDEBAR_GET_PRIVATE (object);
188 
189 	g_free (priv->icon_name);
190 	g_free (priv->primary_text);
191 	g_free (priv->secondary_text);
192 
193 	/* Chain up to parent's finalize() method. */
194 	G_OBJECT_CLASS (e_shell_sidebar_parent_class)->finalize (object);
195 }
196 
197 static void
shell_sidebar_constructed(GObject * object)198 shell_sidebar_constructed (GObject *object)
199 {
200 	EShellView *shell_view;
201 	EShellSidebar *shell_sidebar;
202 	GtkSizeGroup *size_group;
203 	GtkAction *action;
204 	GtkWidget *widget;
205 	gchar *label;
206 	gchar *icon_name;
207 
208 	shell_sidebar = E_SHELL_SIDEBAR (object);
209 	shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
210 	size_group = e_shell_view_get_size_group (shell_view);
211 	action = e_shell_view_get_action (shell_view);
212 
213 	widget = shell_sidebar->priv->event_box;
214 	gtk_size_group_add_widget (size_group, widget);
215 
216 	g_object_get (action, "icon-name", &icon_name, NULL);
217 	e_shell_sidebar_set_icon_name (shell_sidebar, icon_name);
218 	g_free (icon_name);
219 
220 	g_object_get (action, "label", &label, NULL);
221 	e_shell_sidebar_set_primary_text (shell_sidebar, label);
222 	g_free (label);
223 
224 	e_extensible_load_extensions (E_EXTENSIBLE (object));
225 
226 	/* Chain up to parent's constructed() method. */
227 	G_OBJECT_CLASS (e_shell_sidebar_parent_class)->constructed (object);
228 }
229 
230 static void
shell_sidebar_get_preferred_width(GtkWidget * widget,gint * minimum,gint * natural)231 shell_sidebar_get_preferred_width (GtkWidget *widget,
232                                    gint *minimum,
233                                    gint *natural)
234 {
235 	GtkWidget *child;
236 
237 	child = gtk_bin_get_child (GTK_BIN (widget));
238 	gtk_widget_get_preferred_width (child, minimum, natural);
239 
240 	/* Do not use priv->event_box here, otherwise it won't ellipsize. */
241 }
242 
243 static void
shell_sidebar_get_preferred_height(GtkWidget * widget,gint * minimum,gint * natural)244 shell_sidebar_get_preferred_height (GtkWidget *widget,
245                                     gint *minimum,
246                                     gint *natural)
247 {
248 	EShellSidebarPrivate *priv;
249 	gint child_min, child_nat;
250 	GtkWidget *child;
251 
252 	priv = E_SHELL_SIDEBAR_GET_PRIVATE (widget);
253 
254 	child = gtk_bin_get_child (GTK_BIN (widget));
255 	gtk_widget_get_preferred_height (child, minimum, natural);
256 
257 	child = priv->event_box;
258 	gtk_widget_get_preferred_height (child, &child_min, &child_nat);
259 
260 	*minimum += child_min;
261 	*natural += child_nat;
262 }
263 
264 static void
shell_sidebar_size_allocate(GtkWidget * widget,GtkAllocation * allocation)265 shell_sidebar_size_allocate (GtkWidget *widget,
266                              GtkAllocation *allocation)
267 {
268 	EShellSidebarPrivate *priv;
269 	GtkAllocation child_allocation;
270 	GtkRequisition child_requisition;
271 	GtkWidget *child;
272 
273 	priv = E_SHELL_SIDEBAR_GET_PRIVATE (widget);
274 
275 	gtk_widget_set_allocation (widget, allocation);
276 
277 	child = priv->event_box;
278 	gtk_widget_get_preferred_size (child, &child_requisition, NULL);
279 
280 	child_allocation.x = allocation->x;
281 	child_allocation.y = allocation->y;
282 	child_allocation.width = allocation->width;
283 	child_allocation.height = child_requisition.height;
284 
285 	gtk_widget_size_allocate (child, &child_allocation);
286 
287 	child_allocation.y += child_requisition.height;
288 	child_allocation.height =
289 		allocation->height - child_requisition.height;
290 
291 	child = gtk_bin_get_child (GTK_BIN (widget));
292 	if (child != NULL)
293 		gtk_widget_size_allocate (child, &child_allocation);
294 }
295 
296 static void
shell_sidebar_forall(GtkContainer * container,gboolean include_internals,GtkCallback callback,gpointer callback_data)297 shell_sidebar_forall (GtkContainer *container,
298                       gboolean include_internals,
299                       GtkCallback callback,
300                       gpointer callback_data)
301 {
302 	EShellSidebarPrivate *priv;
303 
304 	priv = E_SHELL_SIDEBAR_GET_PRIVATE (container);
305 
306 	if (include_internals && callback && priv->event_box)
307 		callback (priv->event_box, callback_data);
308 
309 	/* Chain up to parent's forall() method. */
310 	GTK_CONTAINER_CLASS (e_shell_sidebar_parent_class)->forall (
311 		container, include_internals, callback, callback_data);
312 }
313 
314 static void
shell_sidebar_submit_alert(EAlertSink * alert_sink,EAlert * alert)315 shell_sidebar_submit_alert (EAlertSink *alert_sink,
316                             EAlert *alert)
317 {
318 	EShellView *shell_view;
319 	EShellContent *shell_content;
320 	EShellSidebar *shell_sidebar;
321 
322 	/* EShellSidebar is a proxy alert sink.  Forward the alert
323 	 * to the EShellContent widget for display to the user. */
324 
325 	shell_sidebar = E_SHELL_SIDEBAR (alert_sink);
326 	shell_view = e_shell_sidebar_get_shell_view (shell_sidebar);
327 	shell_content = e_shell_view_get_shell_content (shell_view);
328 
329 	alert_sink = E_ALERT_SINK (shell_content);
330 	e_alert_sink_submit_alert (alert_sink, alert);
331 }
332 
333 static void
e_shell_sidebar_class_init(EShellSidebarClass * class)334 e_shell_sidebar_class_init (EShellSidebarClass *class)
335 {
336 	GObjectClass *object_class;
337 	GtkWidgetClass *widget_class;
338 	GtkContainerClass *container_class;
339 
340 	g_type_class_add_private (class, sizeof (EShellSidebarPrivate));
341 
342 	object_class = G_OBJECT_CLASS (class);
343 	object_class->set_property = shell_sidebar_set_property;
344 	object_class->get_property = shell_sidebar_get_property;
345 	object_class->dispose = shell_sidebar_dispose;
346 	object_class->finalize = shell_sidebar_finalize;
347 	object_class->constructed = shell_sidebar_constructed;
348 
349 	widget_class = GTK_WIDGET_CLASS (class);
350 	widget_class->get_preferred_width = shell_sidebar_get_preferred_width;
351 	widget_class->get_preferred_height = shell_sidebar_get_preferred_height;
352 	widget_class->size_allocate = shell_sidebar_size_allocate;
353 
354 	container_class = GTK_CONTAINER_CLASS (class);
355 	container_class->forall = shell_sidebar_forall;
356 
357 	/**
358 	 * EShellSidebar:icon-name
359 	 *
360 	 * The named icon is displayed at the top of the sidebar.
361 	 **/
362 	g_object_class_install_property (
363 		object_class,
364 		PROP_ICON_NAME,
365 		g_param_spec_string (
366 			"icon-name",
367 			"Icon Name",
368 			NULL,
369 			NULL,
370 			G_PARAM_READWRITE |
371 			G_PARAM_STATIC_STRINGS));
372 
373 	/**
374 	 * EShellSidebar:primary-text
375 	 *
376 	 * The primary text is displayed in bold at the top of the sidebar.
377 	 **/
378 	g_object_class_install_property (
379 		object_class,
380 		PROP_PRIMARY_TEXT,
381 		g_param_spec_string (
382 			"primary-text",
383 			"Primary Text",
384 			NULL,
385 			NULL,
386 			G_PARAM_READWRITE |
387 			G_PARAM_STATIC_STRINGS));
388 
389 	/**
390 	 * EShellSidebar:secondary-text
391 	 *
392 	 * The secondary text is displayed in a smaller font at the top of
393 	 * the sidebar.
394 	 **/
395 	g_object_class_install_property (
396 		object_class,
397 		PROP_SECONDARY_TEXT,
398 		g_param_spec_string (
399 			"secondary-text",
400 			"Secondary Text",
401 			NULL,
402 			NULL,
403 			G_PARAM_READWRITE |
404 			G_PARAM_STATIC_STRINGS));
405 
406 	/**
407 	 * EShellSidebar:shell-view
408 	 *
409 	 * The #EShellView to which the sidebar widget belongs.
410 	 **/
411 	g_object_class_install_property (
412 		object_class,
413 		PROP_SHELL_VIEW,
414 		g_param_spec_object (
415 			"shell-view",
416 			"Shell View",
417 			NULL,
418 			E_TYPE_SHELL_VIEW,
419 			G_PARAM_READWRITE |
420 			G_PARAM_CONSTRUCT_ONLY |
421 			G_PARAM_STATIC_STRINGS));
422 }
423 
424 static void
e_shell_sidebar_alert_sink_init(EAlertSinkInterface * iface)425 e_shell_sidebar_alert_sink_init (EAlertSinkInterface *iface)
426 {
427 	iface->submit_alert = shell_sidebar_submit_alert;
428 }
429 
430 static void
e_shell_sidebar_init(EShellSidebar * shell_sidebar)431 e_shell_sidebar_init (EShellSidebar *shell_sidebar)
432 {
433 	GtkWidget *widget;
434 	GtkWidget *container;
435 	PangoAttribute *attribute;
436 	PangoAttrList *attribute_list;
437 	const gchar *icon_name;
438 
439 	shell_sidebar->priv = E_SHELL_SIDEBAR_GET_PRIVATE (shell_sidebar);
440 
441 	gtk_widget_set_has_window (GTK_WIDGET (shell_sidebar), FALSE);
442 
443 	widget = gtk_event_box_new ();
444 	gtk_widget_set_parent (widget, GTK_WIDGET (shell_sidebar));
445 	shell_sidebar->priv->event_box = g_object_ref (widget);
446 	gtk_widget_show (widget);
447 
448 	container = widget;
449 
450 	widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
451 	gtk_style_context_add_class (gtk_widget_get_style_context (widget), "header-box");
452 	gtk_container_add (GTK_CONTAINER (container), widget);
453 	gtk_widget_show (widget);
454 
455 	container = widget;
456 
457 	/* Pick a bogus icon name just to get the storage type set. */
458 	icon_name = "evolution";
459 	e_shell_sidebar_set_icon_name (shell_sidebar, icon_name);
460 	widget = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
461 	shell_sidebar->priv->image_widget = widget;
462 	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
463 	gtk_widget_show (widget);
464 
465 	e_binding_bind_property (
466 		shell_sidebar, "icon-name",
467 		widget, "icon-name",
468 		G_BINDING_SYNC_CREATE);
469 
470 	widget = gtk_label_new (NULL);
471 	gtk_label_set_ellipsize (GTK_LABEL (widget), PANGO_ELLIPSIZE_END);
472 	gtk_misc_set_alignment (GTK_MISC (widget), 0.0, 0.5);
473 	gtk_box_pack_start (GTK_BOX (container), widget, TRUE, TRUE, 0);
474 	gtk_widget_show (widget);
475 
476 	attribute_list = pango_attr_list_new ();
477 	attribute = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
478 	pango_attr_list_insert (attribute_list, attribute);
479 	gtk_label_set_attributes (GTK_LABEL (widget), attribute_list);
480 	pango_attr_list_unref (attribute_list);
481 
482 	e_binding_bind_property (
483 		shell_sidebar, "primary-text",
484 		widget, "label",
485 		G_BINDING_SYNC_CREATE);
486 
487 	widget = gtk_label_new (NULL);
488 	gtk_misc_set_alignment (GTK_MISC (widget), 1.0, 0.5);
489 	gtk_box_pack_start (GTK_BOX (container), widget, FALSE, FALSE, 0);
490 	gtk_widget_show (widget);
491 
492 	attribute_list = pango_attr_list_new ();
493 	attribute = pango_attr_scale_new (PANGO_SCALE_SMALL);
494 	pango_attr_list_insert (attribute_list, attribute);
495 	gtk_label_set_attributes (GTK_LABEL (widget), attribute_list);
496 	pango_attr_list_unref (attribute_list);
497 
498 	e_binding_bind_property (
499 		shell_sidebar, "secondary-text",
500 		widget, "label",
501 		G_BINDING_SYNC_CREATE);
502 }
503 
504 /**
505  * e_shell_sidebar_new:
506  * @shell_view: an #EShellView
507  *
508  * Creates a new #EShellSidebar instance belonging to @shell_view.
509  *
510  * Returns: a new #EShellSidebar instance
511  **/
512 GtkWidget *
e_shell_sidebar_new(EShellView * shell_view)513 e_shell_sidebar_new (EShellView *shell_view)
514 {
515 	g_return_val_if_fail (E_IS_SHELL_VIEW (shell_view), NULL);
516 
517 	return g_object_new (
518 		E_TYPE_SHELL_SIDEBAR,
519 		"shell-view", shell_view, NULL);
520 }
521 
522 /**
523  * e_shell_sidebar_check_state:
524  * @shell_sidebar: an #EShellSidebar
525  *
526  * #EShellSidebar subclasses should implement the
527  * <structfield>check_state</structfield> method in #EShellSidebarClass
528  * to return a set of flags describing the current sidebar selection.
529  * Subclasses are responsible for defining their own flags.  This is
530  * primarily used to assist shell views with updating actions (see
531  * e_shell_view_update_actions()).
532  *
533  * Returns: a set of flags describing the current @shell_sidebar selection
534  **/
535 guint32
e_shell_sidebar_check_state(EShellSidebar * shell_sidebar)536 e_shell_sidebar_check_state (EShellSidebar *shell_sidebar)
537 {
538 	EShellSidebarClass *shell_sidebar_class;
539 
540 	g_return_val_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar), 0);
541 
542 	shell_sidebar_class = E_SHELL_SIDEBAR_GET_CLASS (shell_sidebar);
543 	g_return_val_if_fail (shell_sidebar_class != NULL, 0);
544 	g_return_val_if_fail (shell_sidebar_class->check_state != NULL, 0);
545 
546 	return shell_sidebar_class->check_state (shell_sidebar);
547 }
548 
549 /**
550  * e_shell_sidebar_get_shell_view:
551  * @shell_sidebar: an #EShellSidebar
552  *
553  * Returns the #EShellView that was passed to e_shell_sidebar_new().
554  *
555  * Returns: the #EShellView to which @shell_sidebar belongs
556  **/
557 EShellView *
e_shell_sidebar_get_shell_view(EShellSidebar * shell_sidebar)558 e_shell_sidebar_get_shell_view (EShellSidebar *shell_sidebar)
559 {
560 	g_return_val_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar), NULL);
561 
562 	return E_SHELL_VIEW (shell_sidebar->priv->shell_view);
563 }
564 
565 /**
566  * e_shell_sidebar_get_image_widget:
567  * @shell_sidebar: an #EShellSidebar
568  *
569  * Returns the #GtkImage used for the @shell_sidebar. It can be used
570  * to temporarily override the image's content, at least until
571  * the "icon-name" property of the #EShellSidebar changes.
572  *
573  * Returns: the #GtkImage used for the @shell_sidebar
574  *
575  * Since: 3.34
576  **/
577 GtkWidget *
e_shell_sidebar_get_image_widget(EShellSidebar * shell_sidebar)578 e_shell_sidebar_get_image_widget (EShellSidebar *shell_sidebar)
579 {
580 	g_return_val_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar), NULL);
581 
582 	return shell_sidebar->priv->image_widget;
583 }
584 
585 /**
586  * e_shell_sidebar_get_icon_name:
587  * @shell_sidebar: an #EShellSidebar
588  *
589  * Returns the icon name displayed at the top of the sidebar.
590  *
591  * Returns: the icon name for @shell_sidebar
592  **/
593 const gchar *
e_shell_sidebar_get_icon_name(EShellSidebar * shell_sidebar)594 e_shell_sidebar_get_icon_name (EShellSidebar *shell_sidebar)
595 {
596 	g_return_val_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar), NULL);
597 
598 	return shell_sidebar->priv->icon_name;
599 }
600 
601 /**
602  * e_shell_sidebar_set_icon_name:
603  * @shell_sidebar: an #EShellSidebar
604  * @icon_name: a themed icon name
605  *
606  * Sets the icon name displayed at the top of the sidebar.
607  **/
608 void
e_shell_sidebar_set_icon_name(EShellSidebar * shell_sidebar,const gchar * icon_name)609 e_shell_sidebar_set_icon_name (EShellSidebar *shell_sidebar,
610                                const gchar *icon_name)
611 {
612 	g_return_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar));
613 
614 	if (g_strcmp0 (shell_sidebar->priv->icon_name, icon_name) == 0)
615 		return;
616 
617 	g_free (shell_sidebar->priv->icon_name);
618 	shell_sidebar->priv->icon_name = g_strdup (icon_name);
619 
620 	g_object_notify (G_OBJECT (shell_sidebar), "icon-name");
621 }
622 
623 /**
624  * e_shell_sidebar_get_primary_text:
625  * @shell_sidebar: an #EShellSidebar
626  *
627  * Returns the primary text for @shell_sidebar.
628  *
629  * The primary text is displayed in bold at the top of the sidebar.  It
630  * defaults to the shell view's label (as seen on the switcher button),
631  * but typically shows the name of the selected item in the sidebar.
632  *
633  * Returns: the primary text for @shell_sidebar
634  **/
635 const gchar *
e_shell_sidebar_get_primary_text(EShellSidebar * shell_sidebar)636 e_shell_sidebar_get_primary_text (EShellSidebar *shell_sidebar)
637 {
638 	g_return_val_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar), NULL);
639 
640 	return shell_sidebar->priv->primary_text;
641 }
642 
643 /**
644  * e_shell_sidebar_set_primary_text:
645  * @shell_sidebar: an #EShellSidebar
646  * @primary_text: text to be displayed in a bold font
647  *
648  * Sets the primary text for @shell_sidebar.
649  *
650  * The primary text is displayed in bold at the top of the sidebar.  It
651  * defaults to the shell view's label (as seen on the switcher button),
652  * but typically shows the name of the selected item in the sidebar.
653  **/
654 void
e_shell_sidebar_set_primary_text(EShellSidebar * shell_sidebar,const gchar * primary_text)655 e_shell_sidebar_set_primary_text (EShellSidebar *shell_sidebar,
656                                   const gchar *primary_text)
657 {
658 	g_return_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar));
659 
660 	if (g_strcmp0 (shell_sidebar->priv->primary_text, primary_text) == 0)
661 		return;
662 
663 	g_free (shell_sidebar->priv->primary_text);
664 	shell_sidebar->priv->primary_text = e_utf8_ensure_valid (primary_text);
665 
666 	gtk_widget_queue_resize (GTK_WIDGET (shell_sidebar));
667 	g_object_notify (G_OBJECT (shell_sidebar), "primary-text");
668 }
669 
670 /**
671  * e_shell_sidebar_get_secondary_text:
672  * @shell_sidebar: an #EShellSidebar
673  *
674  * Returns the secondary text for @shell_sidebar.
675  *
676  * The secondary text is displayed in a smaller font at the top of the
677  * sidebar.  It typically shows information about the contents of the
678  * selected sidebar item, such as total number of items, number of
679  * selected items, etc.
680  *
681  * Returns: the secondary text for @shell_sidebar
682  **/
683 const gchar *
e_shell_sidebar_get_secondary_text(EShellSidebar * shell_sidebar)684 e_shell_sidebar_get_secondary_text (EShellSidebar *shell_sidebar)
685 {
686 	g_return_val_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar), NULL);
687 
688 	return shell_sidebar->priv->secondary_text;
689 }
690 
691 /**
692  * e_shell_sidebar_set_secondary_text:
693  * @shell_sidebar: an #EShellSidebar
694  * @secondary_text: text to be displayed in a smaller font
695  *
696  * Sets the secondary text for @shell_sidebar.
697  *
698  * The secondary text is displayed in a smaller font at the top of the
699  * sidebar.  It typically shows information about the contents of the
700  * selected sidebar item, such as total number of items, number of
701  * selected items, etc.
702  **/
703 void
e_shell_sidebar_set_secondary_text(EShellSidebar * shell_sidebar,const gchar * secondary_text)704 e_shell_sidebar_set_secondary_text (EShellSidebar *shell_sidebar,
705                                     const gchar *secondary_text)
706 {
707 	g_return_if_fail (E_IS_SHELL_SIDEBAR (shell_sidebar));
708 
709 	if (g_strcmp0 (shell_sidebar->priv->secondary_text, secondary_text) == 0)
710 		return;
711 
712 	g_free (shell_sidebar->priv->secondary_text);
713 	shell_sidebar->priv->secondary_text = e_utf8_ensure_valid (secondary_text);
714 
715 	gtk_widget_queue_resize (GTK_WIDGET (shell_sidebar));
716 	g_object_notify (G_OBJECT (shell_sidebar), "secondary-text");
717 }
718