Renamed src/ to hildon/
[hildon] / hildon / hildon-bread-crumb-trail.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 2007 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Rodrigo Novo <rodrigo.novo@nokia.com>
7  * Author: Xan Lopez <xan.lopez@nokia.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; version 2.1 of
12  * the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
22  * 02110-1301 USA
23  *
24  */
25
26
27 /**
28  * SECTION:hildon-bread-crumb-trail
29  * @short_description: Widget used to represent a specific path in a hierarchical tree.
30  * Stability: Unstable
31  *
32  * HildonBreadCrumbTrail is a GTK widget used to represent the currently active path in
33  * some kind of hierarchical structure (file system, media library, structured document, etc).
34  *
35  * It has built-in support for text and icon bread crumbs, but the trail only requires a very
36  * simple interface to be implemented for its children and thus new types of items can be
37  * implemented if needed. See #HildonBreadCrumb for more details.
38  */
39
40 #undef HILDON_DISABLE_DEPRECATED
41
42 #include <gdk/gdkkeysyms.h>
43
44 #include "hildon-marshalers.h"
45 #include "hildon-bread-crumb-trail.h"
46 #include "hildon-bread-crumb-widget.h"
47
48 #define HILDON_BREAD_CRUMB_TRAIL_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), HILDON_TYPE_BREAD_CRUMB_TRAIL, HildonBreadCrumbTrailPrivate))
49
50 struct _HildonBreadCrumbTrailPrivate
51 {
52   GtkWidget *back_button;
53   GList *item_list;
54   GtkWidget *arrow;
55 };
56
57 /* Signals */
58
59 enum {
60   CRUMB_CLICKED,
61   MOVE_PARENT,
62   LAST_SIGNAL
63 };
64
65 /* Properties */
66
67 enum {
68   PROP_0
69 };
70
71 static void hildon_bread_crumb_trail_size_request (GtkWidget *widget,
72                                                    GtkRequisition *requisition);
73 static void hildon_bread_crumb_trail_size_allocate (GtkWidget *widget,
74                                                     GtkAllocation *allocation);
75 static void hildon_bread_crumb_trail_add (GtkContainer *container,
76                                           GtkWidget *widget);
77 static void hildon_bread_crumb_trail_forall (GtkContainer *container,
78                                              gboolean include_internals,
79                                              GtkCallback callback,
80                                              gpointer callback_data);
81 static void hildon_bread_crumb_trail_remove (GtkContainer *container,
82                                              GtkWidget *widget);
83 static void hildon_bread_crumb_trail_finalize (GObject *object);
84 static void hildon_bread_crumb_trail_scroll_back (GtkWidget *button,
85                                                   HildonBreadCrumbTrail *bct);
86 static void hildon_bread_crumb_trail_update_back_button_sensitivity (HildonBreadCrumbTrail *bct);
87 static void hildon_bread_crumb_trail_move_parent (HildonBreadCrumbTrail *bct);
88
89 static gpointer get_bread_crumb_id (HildonBreadCrumb *item);
90
91 static guint bread_crumb_trail_signals[LAST_SIGNAL] = { 0 };
92
93 /* GType methods */
94
95 G_DEFINE_TYPE (HildonBreadCrumbTrail, hildon_bread_crumb_trail, GTK_TYPE_CONTAINER)
96
97 static void
98 hildon_bread_crumb_trail_class_init (HildonBreadCrumbTrailClass *klass)
99 {
100   GObjectClass *gobject_class = (GObjectClass*)klass;
101   GtkObjectClass *object_class = (GtkObjectClass*)klass;
102   GtkWidgetClass *widget_class = (GtkWidgetClass*)klass;
103   GtkContainerClass *container_class = (GtkContainerClass*)klass;
104   GtkBindingSet *binding_set;
105
106   /* GObject signals */
107   gobject_class->finalize = hildon_bread_crumb_trail_finalize;
108
109   /* GtkWidget signals */
110   widget_class->size_request = hildon_bread_crumb_trail_size_request;
111   widget_class->size_allocate = hildon_bread_crumb_trail_size_allocate;
112
113   /* GtkContainer signals */
114   container_class->add = hildon_bread_crumb_trail_add;
115   container_class->forall = hildon_bread_crumb_trail_forall;
116   container_class->remove = hildon_bread_crumb_trail_remove;
117
118   /* HildonBreadCrumbTrail signals */
119   klass->move_parent = hildon_bread_crumb_trail_move_parent;
120
121   /* Style properties */
122
123 #define _BREAD_CRUMB_TRAIL_MINIMUM_WIDTH 10
124
125   /* FIXME: is this the best way to do it? */
126   gtk_widget_class_install_style_property (widget_class,
127                                            g_param_spec_int ("minimum-width",
128                                                              "Minimum width",
129                                                              "The minimum width in characters the children widgets will request",
130                                                              0,
131                                                              G_MAXINT,
132                                                              _BREAD_CRUMB_TRAIL_MINIMUM_WIDTH,
133                                                              G_PARAM_READABLE));
134
135 #define _BREAD_CRUMB_TRAIL_ARROW_SIZE 34
136
137   gtk_widget_class_install_style_property (widget_class,
138                                            g_param_spec_int ("arrow-size",
139                                                              "Arrow size",
140                                                              "Size of the back button arrow",
141                                                              0,
142                                                              G_MAXINT,
143                                                              _BREAD_CRUMB_TRAIL_ARROW_SIZE,
144                                                              G_PARAM_READABLE));
145   /* Signals */
146   bread_crumb_trail_signals[CRUMB_CLICKED] =
147     g_signal_new ("crumb-clicked",
148                   G_OBJECT_CLASS_TYPE (object_class),
149                   G_SIGNAL_RUN_LAST,
150                   G_STRUCT_OFFSET (HildonBreadCrumbTrailClass, crumb_clicked),
151                   g_signal_accumulator_true_handled, NULL,
152                   _hildon_marshal_BOOLEAN__POINTER,
153                   G_TYPE_BOOLEAN, 1,
154                   G_TYPE_POINTER);
155
156   bread_crumb_trail_signals[MOVE_PARENT] =
157     g_signal_new ("move-parent",
158                   G_OBJECT_CLASS_TYPE (object_class),
159                   G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
160                   G_STRUCT_OFFSET (HildonBreadCrumbTrailClass, move_parent),
161                   NULL, NULL,
162                   g_cclosure_marshal_VOID__VOID,
163                   G_TYPE_NONE,
164                   0);
165                   
166
167   /* Binding set */
168   binding_set = gtk_binding_set_by_class (widget_class);
169
170   gtk_binding_entry_add_signal (binding_set, GDK_Escape, 0,
171                                 "move-parent", 0);
172   gtk_binding_entry_add_signal (binding_set, GDK_BackSpace, 0,
173                                 "move-parent", 0);
174                                 
175   /* Private data */
176   g_type_class_add_private (gobject_class, sizeof (HildonBreadCrumbTrailPrivate));
177 }
178
179 static void
180 hildon_bread_crumb_trail_finalize (GObject *object)
181 {
182   HildonBreadCrumbTrailPrivate *priv = HILDON_BREAD_CRUMB_TRAIL (object)->priv;
183
184   g_list_free (priv->item_list);
185
186   G_OBJECT_CLASS (hildon_bread_crumb_trail_parent_class)->finalize (object);
187 }
188
189 static void
190 hildon_bread_crumb_trail_move_parent (HildonBreadCrumbTrail *bct)
191 {
192   if (g_list_length (bct->priv->item_list) > 1)
193     {
194       g_signal_emit_by_name (HILDON_BREAD_CRUMB (bct->priv->item_list->next->data),
195                              "crumb-activated");
196     }
197 }
198
199 static void
200 hildon_bread_crumb_trail_size_request (GtkWidget *widget,
201                                        GtkRequisition *requisition)
202 {
203   GList *p;
204   GtkRequisition child_requisition;
205   HildonBreadCrumbTrail *bct;
206   HildonBreadCrumbTrailPrivate *priv;
207   gint minimum_width, width = 0;
208   PangoLayout *layout;
209   gchar *tmp = NULL;
210
211   bct= HILDON_BREAD_CRUMB_TRAIL (widget);
212   priv = bct->priv;
213
214   requisition->height = 0;
215   requisition->width = 0;
216
217   gtk_widget_size_request (priv->back_button, &child_requisition);
218   requisition->width = child_requisition.width;
219   requisition->height = child_requisition.height;
220
221   if (priv->item_list)
222     {
223       /* Add minimum width for one item */
224       /* TODO: this can be probably cached */
225       gtk_widget_style_get (widget,
226                             "minimum-width", &minimum_width,
227                             NULL);
228
229       tmp = g_strnfill ((gsize)minimum_width, 'm');
230       layout = gtk_widget_create_pango_layout (widget, tmp);
231       g_free (tmp);
232       pango_layout_get_size (layout, &width, NULL);
233       requisition->width += PANGO_PIXELS (width);
234       g_object_unref (layout);
235     }
236
237   /* Button requisitions */
238   for (p = priv->item_list; p; p = p->next)
239     {
240       GtkWidget *child = GTK_WIDGET (p->data);
241
242       if (GTK_WIDGET_VISIBLE (child))
243         gtk_widget_size_request (child, &child_requisition);
244     }
245
246   /* Border width */
247   requisition->width += GTK_CONTAINER (widget)->border_width * 2;
248   requisition->height += GTK_CONTAINER (widget)->border_width * 2;
249
250   widget->requisition = *requisition;
251 }
252
253 /* Document me please */
254
255 static void
256 hildon_bread_crumb_trail_size_allocate (GtkWidget *widget,
257                                         GtkAllocation *allocation)
258 {
259   GtkRequisition req;
260   gint natural_width, natural_height;
261   HildonBreadCrumb *item;
262   GtkAllocation child_allocation;
263   GtkRequisition child_requisition;
264   GtkWidget *child;
265   gint allocation_width;
266   gint border_width, width;
267   gint extra_space;
268   GList *p, *first_show, *first_hide;
269   gint back_button_size;
270   HildonBreadCrumbTrailPrivate *priv = HILDON_BREAD_CRUMB_TRAIL (widget)->priv;
271   gboolean rtl;
272
273   /* Get the rtl status */
274   rtl = (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL);
275
276   widget->allocation = *allocation;
277
278   border_width = (gint) GTK_CONTAINER (widget)->border_width;
279   allocation_width = allocation->width - 2 * border_width;
280
281   /* Allocate the back button */
282   if (rtl)
283     child_allocation.x = allocation->width - border_width;
284   else
285     child_allocation.x = allocation->x + border_width;
286
287   child_allocation.y = allocation->y + border_width;
288   gtk_widget_get_child_requisition (priv->back_button, &child_requisition);
289   /* We want the back button to be a square */
290   back_button_size = MAX (child_requisition.width, child_requisition.height);
291   child_allocation.width = child_allocation.height = back_button_size;
292
293   if (rtl)
294     child_allocation.x -= back_button_size;
295
296   gtk_widget_size_allocate (priv->back_button, &child_allocation);
297
298   if (!rtl)
299     child_allocation.x += back_button_size;
300
301   /* If there are no buttons there's nothing else to do */
302   if (priv->item_list == NULL)
303     return;
304
305   /* We find out how many buttons can we show, starting from the
306      the last one in the logical path (the first item in the list) */
307
308   width = back_button_size;
309   p = priv->item_list;
310   first_show = NULL;
311   first_hide = NULL; 
312   extra_space = 0;
313
314   for (p = priv->item_list; p; p = p->next)
315     {
316       item = HILDON_BREAD_CRUMB (p->data);
317       child = GTK_WIDGET (item);
318
319       /* Does the widget fit with its natural size? */
320       hildon_bread_crumb_get_natural_size (item,
321                                            &natural_width,
322                                            &natural_height);
323
324       if (width + natural_width <= allocation_width)
325         {
326           /* Yes, it does */
327           first_show = p;
328           first_hide = p->next;
329           width += natural_width;
330         }
331       else
332         {
333           /* No, it doesn't. Allocate as much as possible
334              and stop */
335           child_allocation.width = allocation_width - width;
336
337           gtk_widget_size_request (child, &req);
338
339           if (child_allocation.width > req.width)
340             {
341               first_hide = p->next;
342               gtk_widget_set_child_visible (child, TRUE);
343
344               if (rtl)
345                 child_allocation.x -= child_allocation.width;
346
347               gtk_widget_size_allocate (child, &child_allocation);
348
349               if (!rtl)
350                 child_allocation.x += child_allocation.width;
351             }
352           else
353             {
354               extra_space = child_allocation.width;
355             }
356
357           break;
358         }
359     }
360
361   /* Not enough items to fill the breadcrumb? */
362   if (p == NULL && width < allocation_width)
363     {
364       extra_space = allocation_width - width;
365     }
366
367   /* Allocate the other buttons */
368   for (p = first_show; p; p = p->prev)
369     {
370       item = HILDON_BREAD_CRUMB (p->data);
371       child = GTK_WIDGET (item);
372
373       /* Does the widget fit with its natural size? */
374       hildon_bread_crumb_get_natural_size (item,
375                                            &natural_width,
376                                            &natural_height);
377
378       /* If I'm the last and there's extra space, use it */
379       if (p->prev == NULL && extra_space != 0)
380         {
381           natural_width += extra_space;
382         }
383
384       child_allocation.width = natural_width;
385       gtk_widget_set_child_visible (child, TRUE);
386
387       if (rtl)
388         child_allocation.x -= child_allocation.width;
389
390       gtk_widget_size_allocate (child, &child_allocation);
391
392       if (!rtl)
393         child_allocation.x += child_allocation.width;
394     }
395
396   for (p = first_hide; p; p = p->next)
397     {
398       item = HILDON_BREAD_CRUMB (p->data);
399       gtk_widget_set_child_visible (GTK_WIDGET (item), FALSE);
400     }
401 }
402
403 static gpointer
404 get_bread_crumb_id (HildonBreadCrumb *item)
405 {
406   return g_object_get_data (G_OBJECT (item), "bread-crumb-id");
407 }
408
409 static void
410 crumb_activated_cb (GtkWidget *button,
411                     HildonBreadCrumbTrail *bct)
412 {
413   gboolean signal_handled = FALSE;
414
415   g_signal_emit (bct, bread_crumb_trail_signals[CRUMB_CLICKED], 0,
416                  get_bread_crumb_id (HILDON_BREAD_CRUMB (button)),
417                  &signal_handled);
418
419   if (signal_handled == FALSE)
420     {
421       GtkWidget *child;
422       gboolean focus_last_item = FALSE;
423       HildonBreadCrumbTrailPrivate *priv;
424
425       priv = bct->priv;
426
427       child = GTK_WIDGET (priv->item_list->data);
428
429       /* We remove the tip of the list until we hit the clicked button */
430       while (child && child != button)
431         {
432           if (GTK_WIDGET_HAS_FOCUS (child))
433             focus_last_item = TRUE;
434
435           gtk_container_remove (GTK_CONTAINER (bct), child);
436
437           if (priv->item_list == NULL)
438               return;
439
440           child = GTK_WIDGET (priv->item_list->data);
441         }
442
443       if (focus_last_item)
444         gtk_widget_grab_focus (GTK_WIDGET (bct->priv->item_list->data));
445     }
446 }
447
448 static void
449 hildon_bread_crumb_trail_add (GtkContainer *container,
450                               GtkWidget *widget)
451 {
452   gtk_widget_set_parent (widget, GTK_WIDGET (container));
453
454   if (HILDON_IS_BREAD_CRUMB (widget))
455     {
456       HildonBreadCrumbTrail *bct = HILDON_BREAD_CRUMB_TRAIL (container);
457
458       g_signal_connect (G_OBJECT (widget), "crumb-activated",
459                         G_CALLBACK (crumb_activated_cb), container);
460
461       bct->priv->item_list = g_list_prepend (bct->priv->item_list, widget);
462
463       hildon_bread_crumb_trail_update_back_button_sensitivity (bct);
464     }
465 }
466
467 static void
468 hildon_bread_crumb_trail_forall (GtkContainer *container,
469                                  gboolean include_internals,
470                                  GtkCallback callback,
471                                  gpointer callback_data)
472 {
473   g_return_if_fail (callback != NULL);
474   g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (container));
475
476   GList *children;
477   HildonBreadCrumbTrailPrivate *priv = HILDON_BREAD_CRUMB_TRAIL (container)->priv;
478
479   children = priv->item_list;
480
481   while (children)
482     {
483       GtkWidget *child;
484       child = GTK_WIDGET (children->data);
485       children = children->next;
486
487       (*callback) (child, callback_data);
488     }
489
490   if (include_internals && priv->back_button)
491     {
492       (*callback) (priv->back_button, callback_data);
493     }
494 }
495
496 static void
497 hildon_bread_crumb_trail_remove (GtkContainer *container,
498                                  GtkWidget *widget)
499 {
500   GList *p, *next;
501   HildonBreadCrumbTrailPrivate *priv;
502   gboolean was_visible = GTK_WIDGET_VISIBLE (widget);
503
504   priv = HILDON_BREAD_CRUMB_TRAIL (container)->priv;
505
506   p = priv->item_list;
507
508   while (p)
509     {
510       next = p->next;
511
512       if (widget == GTK_WIDGET (p->data))
513         {
514           g_signal_handlers_disconnect_by_func (widget, G_CALLBACK (crumb_activated_cb),
515                                                 HILDON_BREAD_CRUMB_TRAIL (container));
516           gtk_widget_unparent (widget);
517
518           priv->item_list = g_list_delete_link (priv->item_list, p);
519
520           hildon_bread_crumb_trail_update_back_button_sensitivity (HILDON_BREAD_CRUMB_TRAIL (container));
521
522           if (was_visible)
523             {
524               gtk_widget_queue_resize (GTK_WIDGET (container));
525             }
526         }
527
528       p = next;
529     }
530 }
531
532 static void
533 hildon_bread_crumb_trail_update_back_button_sensitivity (HildonBreadCrumbTrail *bct)
534 {
535   guint list_length;
536   HildonBreadCrumbTrailPrivate *priv = bct->priv;
537
538   list_length = g_list_length (priv->item_list);
539
540   if (list_length <= 1)
541     {
542       gtk_widget_set_sensitive (priv->back_button, FALSE);
543     }
544   else
545     {
546       gtk_widget_set_sensitive (priv->back_button, TRUE);
547     }
548 }
549
550 static GtkWidget*
551 create_back_button (HildonBreadCrumbTrail *bct)
552 {
553   GtkWidget *button;
554   GtkWidget *arrow;
555   gint arrow_size;
556
557   gtk_widget_push_composite_child ();
558
559   button = gtk_button_new ();
560   gtk_widget_set_name (button, "hildon-bread-crumb-back-button");
561   gtk_widget_set_sensitive (button, FALSE);
562
563   arrow = gtk_arrow_new (GTK_ARROW_LEFT, GTK_SHADOW_NONE);
564   bct->priv->arrow = arrow;
565   gtk_widget_style_get (GTK_WIDGET (bct),
566                         "arrow-size", &arrow_size,
567                         NULL);
568   gtk_widget_set_size_request (arrow, arrow_size, arrow_size);
569
570   gtk_container_add (GTK_CONTAINER (button), arrow);
571   gtk_container_add (GTK_CONTAINER (bct), button);
572   gtk_widget_show_all (button);
573
574   gtk_widget_pop_composite_child ();
575
576   return button;
577 }
578
579 static void
580 hildon_bread_crumb_trail_init (HildonBreadCrumbTrail *bct)
581 {
582   HildonBreadCrumbTrailPrivate *priv = HILDON_BREAD_CRUMB_TRAIL_GET_PRIVATE (bct);
583
584   GTK_WIDGET_SET_FLAGS (bct, GTK_NO_WINDOW);
585   gtk_widget_set_redraw_on_allocate (GTK_WIDGET (bct), FALSE);
586
587   bct->priv = priv;
588   priv->item_list = NULL;
589
590   priv->back_button = create_back_button (bct);
591   g_signal_connect (priv->back_button, "clicked",
592                     G_CALLBACK (hildon_bread_crumb_trail_scroll_back),
593                     bct);
594 }
595
596 static void
597 hildon_bread_crumb_trail_scroll_back (GtkWidget *button,
598                                       HildonBreadCrumbTrail *bct)
599 {
600   hildon_bread_crumb_trail_move_parent (bct);
601 }
602
603 static void
604 attach_bread_crumb (HildonBreadCrumbTrail *bct,
605                     GtkWidget *bread_crumb,
606                     gpointer id,
607                     GDestroyNotify destroy)
608 {
609   g_object_set_data_full (G_OBJECT (bread_crumb), "bread-crumb-id", id, destroy);
610
611   gtk_container_add (GTK_CONTAINER (bct), bread_crumb);
612
613   gtk_widget_show (bread_crumb);
614 }
615
616 /* PUBLIC API */
617
618 /**
619  * hildon_bread_crumb_trail_new:
620  * 
621  * Creates a new #HildonBreadCrumbTrail widget.
622  *
623  * Returns: a #GtkWidget pointer of newly created bread crumb trail
624  * widget
625  *
626  * Stability: Unstable
627  */
628
629 GtkWidget*
630 hildon_bread_crumb_trail_new (void)
631 {
632   return GTK_WIDGET (g_object_new (HILDON_TYPE_BREAD_CRUMB_TRAIL, NULL));
633 }
634
635 /**
636  * hildon_bread_crumb_trail_push:
637  * @bct: pointer to #HildonBreadCrumbTrail
638  * @item: the #HildonBreadCrumb to be added to the trail
639  * @id: optional id for the bread crumb
640  * @destroy: GDestroyNotify callback to be called when the bread crumb is destroyed
641  *
642  * Adds a new bread crumb to the end of the trail.
643  *
644  * Stability: Unstable
645  */
646
647 void
648 hildon_bread_crumb_trail_push (HildonBreadCrumbTrail *bct,
649                                HildonBreadCrumb *item,
650                                gpointer id,
651                                GDestroyNotify destroy)
652 {
653   GtkWidget *widget;
654
655   g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct));
656   g_return_if_fail (HILDON_IS_BREAD_CRUMB (item));
657
658   widget = GTK_WIDGET (item);
659
660   attach_bread_crumb (bct, widget, id, destroy);
661 }
662
663 /**
664  * hildon_bread_crumb_trail_push_text:
665  * @bct: pointer to #HildonBreadCrumbTrail
666  * @text: content of the new bread crumb
667  * @id: optional id for the bread crumb
668  * @destroy: GDestroyNotify callback to be called when the bread crumb is destroyed
669  *
670  * Adds a new bread crumb to the end of the trail containing the specified text.
671  *
672  * Stability: Unstable
673  */
674
675 void
676 hildon_bread_crumb_trail_push_text (HildonBreadCrumbTrail *bct,
677                                     const gchar *text,
678                                     gpointer id,
679                                     GDestroyNotify destroy)
680 {
681   GtkWidget *widget;
682
683   g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct));
684   g_return_if_fail (text != NULL);
685
686   widget = _hildon_bread_crumb_widget_new_with_text (text);
687   if (bct->priv->item_list == NULL)
688     {
689       g_object_set (G_OBJECT (widget), "show-separator", FALSE, NULL);
690     }
691   attach_bread_crumb (bct, widget, id, destroy);
692 }
693
694 /**
695  * hildon_bread_crumb_trail_push_icon:
696  * @bct: pointer to #HildonBreadCrumbTrail
697  * @text: content of the new bread crumb
698  * @icon: a widget to set as the icon in the bread crumb
699  * @id: optional id for the bread crumb
700  * @destroy: GDestroyNotify callback to be called when the bread crumb is destroyed
701  *
702  * Adds a new bread crumb to the end of the trail containing the specified text and
703  * icon.
704  *
705  * Stability: Unstable
706  */
707
708 void
709 hildon_bread_crumb_trail_push_icon (HildonBreadCrumbTrail *bct,
710                                     const gchar *text,
711                                     GtkWidget *icon,
712                                     gpointer id,
713                                     GDestroyNotify destroy)
714 {
715   GtkWidget *widget;
716
717   g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct));
718   g_return_if_fail (text != NULL);
719   g_return_if_fail (GTK_IS_WIDGET (icon));
720
721   widget = _hildon_bread_crumb_widget_new_with_icon (icon, text);
722   if (bct->priv->item_list == NULL)
723     {
724       g_object_set (G_OBJECT (widget), "show-separator", FALSE, NULL);
725     }
726   attach_bread_crumb (bct, widget, id, destroy);
727 }
728
729 /**
730  * hildon_bread_crumb_trail_pop:
731  * @bct: pointer to #HildonBreadCrumbTrail
732  *
733  * Removes the last bread crumb from the trail.
734  *
735  * Stability: Unstable
736  */
737
738 void
739 hildon_bread_crumb_trail_pop (HildonBreadCrumbTrail *bct)
740 {
741   GtkWidget *child;
742   HildonBreadCrumbTrailPrivate *priv;
743
744   g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct));
745
746   priv = bct->priv;
747
748   if (priv->item_list == NULL)
749     return;
750
751   if (priv->item_list)
752     {
753       child = GTK_WIDGET (priv->item_list->data);
754       gtk_container_remove (GTK_CONTAINER (bct), child);
755     }
756
757   hildon_bread_crumb_trail_update_back_button_sensitivity (bct);
758 }
759
760 /**
761  * hildon_bread_crumb_trail_clear:
762  * @bct: pointer to #HildonBreadCrumbTrail
763  *
764  * Removes all the bread crumbs from the bread crumb trail.
765  *
766  * Stability: Unstable
767  */
768
769 void
770 hildon_bread_crumb_trail_clear (HildonBreadCrumbTrail *bct)
771 {
772   HildonBreadCrumbTrailPrivate *priv;
773
774   g_return_if_fail (HILDON_IS_BREAD_CRUMB_TRAIL (bct));
775
776   priv = bct->priv;
777
778   while (priv->item_list)
779     {
780       hildon_bread_crumb_trail_pop (bct);
781     }
782
783   /*
784     Sensitivity hack from hell. We need to do this while
785      http://bugzilla.gnome.org/show_bug.cgi?id=56070 is not
786      fixed to allow repeated clicking on the back button if
787      someone clears and rebuilds the trail when it's clicked
788   */
789   gtk_widget_hide (priv->back_button);
790   gtk_widget_show (priv->back_button);
791 }